Page 1 of 1

[SOLVED] What does $1 mean in shell scripts?

PostPosted: Apr 30th, '13, 23:31
by ofbodur
would someone please explain what does while ["$1"] mean in the code below? I see it many times in many scripts. What does it refer to?

I also wonder what if [ "$1" = "-i" ] means...

Code: Select all
#!/bin/bash

while [ "$1" ]
do
if [ "$1" = "-i" ] then
infile="$2"
shift 2
elif [ "$1" = "-o" ]
then
outfile="$2"
shift 2
else
echo "Program $0 does not recognize option $1"
fi
done
tr a-z A-Z <$infile >$outfile

Re: $1

PostPosted: May 1st, '13, 10:18
by doktor5000
Next time please use a more meaningful thread title, nobody will find your thread with that title via search function.

You probably should read some basics about shell scripting first. $1 is the first argument you pass to a script.

Check http://www.tldp.org/LDP/Bash-Beginners-Guide/html/
or http://tldp.org/HOWTO/Bash-Prog-Intro-HOWTO.html
or http://tldp.org/LDP/abs/html/

Re: [SOLVED] What does $1 mean in shell scripts?

PostPosted: May 1st, '13, 10:22
by ofbodur
thanks doc

Re: [SOLVED] What does $1 mean in shell scripts?

PostPosted: May 1st, '13, 10:39
by doktor5000
This wouldn't happen if you try to learn to walk before you want to run ;)
Use one tutorial, and stick to it. The best that i've seen so far is http://steve-parker.org/sh/sh.shtml