simple if command


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers simple if command
# 1  
Old 11-18-2008
simple if command

#! /bin/sh

envname=$1

if [ "${envname}" =""]; then
echo usage : `basename $0` envname
exit -1
fi

can someone explain what exactly this does
# 2  
Old 11-18-2008
When you invoke a script
Code:
myscritpname.sh arg1 arg2

you can enter whatever arguments you want, whether the script likes it or not.
This script will tell you if the number of arguments you gave it is not equal to 1
First it sets envame = parameter #1
Then it tests to see if the envanme variable is "empty". If the variable is empty the script print a message
showing the correct usage of the script, then exits with error status.

FWIW the correct way to do this in modern POSIX shells is:
Code:
if [ -z $envname ] ; then
 echo usage : `basename $0` envname
 exit -1
fi

 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

A simple awk command

Hi there, given the file FIELD1 FIELD2 FIELD3 FIELD4 FIELD5 FIELD6 FIELD7 FIELD8 FIELD9 FIELD10 FIELD11 Why does not awk '$6 == "FIELD6" {$6=="GREEN"}1' file do the work and replace"FIELD6" by "GREEN"? And second question, what is the purpose of the "1" at the end of... (5 Replies)
Discussion started by: la2015
5 Replies

2. Shell Programming and Scripting

please describe me some simple command

Hi everyone I'm new here and I don't know some command of unix, please help by describe me how it work, I study unix command by myself and can't search exactly means so...Thanks :D sqlplus -s /nolog @${SQLFILE} ${file_type} >> ${OUTPUT_FILE} date "+%Y%m%d%H%M%S" $/usr/bin/echo "INFO : $1"... (2 Replies)
Discussion started by: zound617
2 Replies

3. Shell Programming and Scripting

Help with simple grep command

I am currently having a problem with displaying multiple occurences of a line using grep/sed combination. Let's say that I do grep "$anything" $file. When I do this it only displays a single line, but if I do grep -c "$anything" $file it says that there are 3 occurences of $anything, but how can... (15 Replies)
Discussion started by: puttster
15 Replies

4. Shell Programming and Scripting

awk command for simple join command but based on 2 columns

input1 a_a a/a 10 100 a1 a_a 20 200 b1 b_b 30 300 input2 a_a a/a xxx yyy a1 a1 lll ppp b1 b_b kkk ooo output a_a a/a 10 100 xxx yyy (2 Replies)
Discussion started by: ruby_sgp
2 Replies

5. Shell Programming and Scripting

alias a simple ls -l command

how do I alias the following command: ls -l |egrep 'drw|dr-|d--|d-w' The alias command needs single quotes and so does the above command, so this does not work: alias LSDIR 'ls -l |egrep 'drw|dr-|d--|d-w' ' My problem is how do I get a listing of only directories? Solaris 8 SUN Ultra 10... (4 Replies)
Discussion started by: ajp7701
4 Replies

6. Shell Programming and Scripting

Simple AWK command?

I am not that good with AWK. Is there a simple awk command I could use to get the word "this" from the following text besides using "awk -F ":" '{print $2} | awk -F " " '{print $1}"? :this is:that is: (6 Replies)
Discussion started by: 2dumb
6 Replies

7. Shell Programming and Scripting

Help with a simple loop command!

Hi! I'm having problems to get this simple script done: I need to insert 50 lines with the value from the variable dtm=`date +"%d"` into a new file, how do I do that using the "for" or "while" loop commands ? Is there any other command I can use to do that ? I'm new to shell scripting, as you can... (8 Replies)
Discussion started by: dfs
8 Replies

8. UNIX for Dummies Questions & Answers

Simple sed command

Hi, I have the following file: --# --#line1 --#line2 --#line3 --# --#line4 --#line5 and I want to use something like: sed 's/--#/newline/g' file > newfile to substitute the lines containing only '--#', but when I try, it replaces every instance of '--#' with 'newline' and I... (7 Replies)
Discussion started by: Dave724001
7 Replies

9. Shell Programming and Scripting

probably simple SED-command ...

Hello, I've got a problem with SED. It's my intention to shorten a file path (removing the file name) with the help of SED. Something like: tmp\folder1\folder2\blah.txt has to be transformed to tmp\folder1\folder2\. I suppose, it's on the tip of my tongue. Perhaps it's close to: sed... (2 Replies)
Discussion started by: sysadv
2 Replies

10. UNIX for Dummies Questions & Answers

Need help with a simple command

You don't know the name of the command that could do a particular task. What command could you run to find the name of the command? (4 Replies)
Discussion started by: kurtbudd1
4 Replies
Login or Register to Ask a Question