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

This forum is dedicated to basic help and support :

Ask here your questions about basic installation and usage of Mageia. For example you may post here all your questions about getting Mageia isos and installing it, configuring your printer, using your word processor etc.

Try to ask your questions in the right sub-forum with as much details as you can gather. the more precise the question will be, the more likely you are to get a useful answer

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

Postby ofbodur » Apr 30th, '13, 23:31

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
There is nothing worse than having failed to explain what you believe.
User avatar
ofbodur
 
Posts: 35
Joined: Mar 10th, '13, 12:33
Location: Istanbul

Re: $1

Postby doktor5000 » May 1st, '13, 10:18

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/
Cauldron is not for the faint of heart!
Caution: Hot, bubbling magic inside. May explode or cook your kittens!
----
Disclaimer: Beware of allergic reactions in answer to unconstructive complaint-type posts
User avatar
doktor5000
 
Posts: 18062
Joined: Jun 4th, '11, 10:10
Location: Leipzig, Germany

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

Postby ofbodur » May 1st, '13, 10:22

thanks doc
There is nothing worse than having failed to explain what you believe.
User avatar
ofbodur
 
Posts: 35
Joined: Mar 10th, '13, 12:33
Location: Istanbul

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

Postby doktor5000 » May 1st, '13, 10:39

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
Cauldron is not for the faint of heart!
Caution: Hot, bubbling magic inside. May explode or cook your kittens!
----
Disclaimer: Beware of allergic reactions in answer to unconstructive complaint-type posts
User avatar
doktor5000
 
Posts: 18062
Joined: Jun 4th, '11, 10:10
Location: Leipzig, Germany


Return to Basic support

Who is online

Users browsing this forum: No registered users and 1 guest