LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   Linux Bash shell Scrpt help (https://www.linuxquestions.org/questions/linux-general-1/linux-bash-shell-scrpt-help-478520/)

samBl 08-29-2006 03:11 PM

Linux Bash shell Scrpt help
 
I'm trying to make a shell script for a class in college where it will tack to entered arguments and display them on the screen as " Your first argument was ___" and "your Second argument was ____". If more or less then two arguments are entered the program will quit.
So it I entered:
./usage.bash hi there
my out put should be:
your first argument was hi
your second argument was there.

Here is what I have so far:
#!/bin/bash
if [ ]
then
echo "Your first argument was $1"
echo "Your second argument was $2"
else
exit 127
fi
I need to figure out how to test to see if I have two arguments.

zhangmaike 08-29-2006 03:58 PM

Use $#. It contains the number of arguments.

samBl 08-29-2006 04:17 PM

Thank you I just could not remember. Is there a good online resource that might be able to help me with my scripting?

zhangmaike 08-29-2006 05:29 PM

Go to tldp.org, search for bash scripting. Google's great, too.

The best guide I've seen is here: http://www.tldp.org/LDP/abs/html/

Honestly, just search around yourself. It's hard not to find good bash documentation.


All times are GMT -5. The time now is 06:03 AM.