programming with linux shell tutorial by example passing arguments to a script
RegisterLogin
Webune Forums » Linux Commands » programming with linux shell tutorial by example passing arguments to a script
programming with linux shell tutorial by example passing arguments to a script
Post Description: programming with linux shell tutorial by example passing arguments to a script
Tags: programming, with, linux, shell, tutorial, by, example, passing, arguments, to, a, script
This Post Was Posted On Feb 29, 2008 By linux #572
Post Description: programming with linux shell tutorial by example passing arguments to a script
Tags: programming, with, linux, shell, tutorial, by, example, passing, arguments, to, a, script
This Post Was Posted On Feb 29, 2008 By linux #572
programming with linux shell tutorial by example passing arguments to a script by linux
step 1. create a file called my_script
nano my_script
step 2. add the following lines and save the file
echo hello $USER
echo 'The contents of variable $1 is ' $1
echo 'The contents of variable $2 is ' $2
echo 'The contents of variable $3 is ' $3
echo 'The contents of variable $0 is ' $0
echo 'The contents of variable $* is ' $*
echo 'The contents of variable $# is ' $#
echo 'The contents of variable $$ is ' $$
echo 'The contents of variable $1 is ' $1
echo 'The contents of variable $2 is ' $2
echo 'The contents of variable $3 is ' $3
echo 'The contents of variable $0 is ' $0
echo 'The contents of variable $* is ' $*
echo 'The contents of variable $# is ' $#
echo 'The contents of variable $$ is ' $$
* to save the file just hit CNTL + X and say yes at the prompt to save the file
step 3. make the file executable
chmod 755 my_script
step 4. run the script and declare the variables
./my_script Wallpaperama Wallpapers Learn Linux Tutorial Hosting
step 5. the output should look similar to something like this
hello my_user_name
The contents of variable $1 is Wallpaperama
The contents of variable $2 is Wallpapers
The contents of variable $3 is Learn
The contents of variable $0 is ./my_script
The contents of variable $* is Wallpaperama Wallpapers Learn Linux Tutorial Hosting
The contents of variable $# is 6
The contents of variable $$ is 2071
The contents of variable $1 is Wallpaperama
The contents of variable $2 is Wallpapers
The contents of variable $3 is Learn
The contents of variable $0 is ./my_script
The contents of variable $* is Wallpaperama Wallpapers Learn Linux Tutorial Hosting
The contents of variable $# is 6
The contents of variable $$ is 2071
Leave Your Comments
©2011 Webune Forums - Wed Dec 21, 2011 7:43 pm
Powered by: Webune Forums V3
Powered by: Webune Forums V3