HPUX - Shell Programming
shell programming
$ cat a.c
main(){
for(;;);
} //needs compile, not a shell script
$ cat myprog
# this is the program myprog
date
ls -F
//shell script
shell script and child process
$ color=blue
$ cat color1
echo You are now running program: color1
echo the value of the variable color is: $color
$ color1
You are now running program: color1
the value of the variable color is:
$ cat color4
echo There are $# command line arguments, 인수의 수
echo They are $*
echo The first command line argument is $1
$ color4 red white blue black
There are 4 command line arguments
They are red white blue black
The first command line argument is red
read command
{
$ cat color6
echo This program prompts for user input
echo "Please enter your favorite two colors -> \c" // 자동 newline 방지 "\c"
read color_a color_b
echo The colors you entered are: $color_b $color_a
Additional Techiques
#!/usr/bin/"shell_name" define shell script
Debugging mode
$ sh -x color5 A B C D E F G
+ orig_args=A B C D E F G //code를read한 부분
+ echo There are 7 command line arguments
There are 7 command line arguments //terminal에서 표시되는 부분
+ echo They are A B C D E F G
They are A B C D E F G
+ echo Shifting two arguments
Shifting two arguments
+ shift 2
+ echo There are 5 command line arguments
There are 5 command line arguments
+ echo They are C D E F G
They are C D E F G
+ echo Shifting two arguments
Shifting two arguments
+ shift 2
+ final_args=E F G
+ echo Original arguments are: A B C D E F G
Original arguments are: A B C D E F G
+ echo Final arguments are: E F G
Final arguments are: E F G
Exercise
echo welcome $(whoami)
date
who
echo "\n\n"
who am i | tr -s " " | cut -f1,2 -d" "
echo bye bye
========
grep user /etc/passwd |pr -t -6
echo enter your name:
read usr_name
grep $usr_name /etc/passwd | cut -f6 -d:| ls