05-23-2007
Parameter Checking
Hi all,
My script has 2 mandatory and 1 optional paramter. If the third parameter(optional) one is null the it should take a default value say 3. Can any one please write a simple code.
sh test.sh 1 2 3
var1=$1
var2=$2
if [ -z $3 ]
then
var3=3
fi
echo " the third variable $var3"
But this is erroring out saying " test.sh: test: argument expected"
Thanks in advance
Ammu
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
Say I write something like the following:
var1=1
var2=2
for int in 1 2
do
echo "\$var$int"
done
I want the output to be:
1
2
Instead I get something like:
$var1
$var2 (2 Replies)
Discussion started by: Awanka
2 Replies
2. UNIX for Dummies Questions & Answers
Hi,
I will pass 3 parameters for a script.I have to check the file name and create a new file name with time stamp.
the parameters which i'm passing are
/dir/stg/filename.txt
/dir/path/head.txt
/dir/path/tail.txt
Now i have to check filename like :
if it is a.txt i have to create... (2 Replies)
Discussion started by: ammu
2 Replies
3. UNIX for Dummies Questions & Answers
I have written a function that fills an array and another function where if a parameter is supplied it will jump to that part of the array and cat it to the screen.
I need to put in some checks to make sure the parameter supplied is firstly a number and then not a number great than the length of... (2 Replies)
Discussion started by: magnia
2 Replies
4. Shell Programming and Scripting
Hi
I am looking for a unix command or a small shell script which can takes one parameter and then searches for the passed in the parameter in any or all files under say /home/dev/
Can anyone please help me on this? (3 Replies)
Discussion started by: pankaj80
3 Replies
5. Shell Programming and Scripting
I need to check if the parameters are correctly passed based on the Environment I am in.
For e.g when I am in dev the 1st paramter needs to be either A OR B OR C OR D
similarly when I am in qa the parameter needs to be either e or f
so i need to write a case staement or a if statement to... (1 Reply)
Discussion started by: dsravan
1 Replies
6. Shell Programming and Scripting
i am passing input parameter 'one_two' to the script , the script output should display the result as below
one_1two
one_2two
one_3two
if
then
echo " Usage : <$0> <DATABASE> "
exit 0
else
for DB in 1 2 3
do
DBname=`$DATABASE | awk -F "_" '{print $1_${DB}_$2}`
done
fi (5 Replies)
Discussion started by: only4satish
5 Replies
7. Shell Programming and Scripting
hi all,
i have a parameter file of following format, i want a method which can get the value of specific parameter.
parameter file format:
<Parameter Name="FileLocationWindows">
<Description>
The directory location of the logger file.
... (1 Reply)
Discussion started by: laxmikant.hcl
1 Replies
8. Shell Programming and Scripting
Hi,
I have the following files.
->cat scr.sh
export TMP_DIR=/home/user/folder1
export TMP_DIR_2=/home/user/folder2
while read line
do
cat "$line"
done<file_list.dat
------------------------
-> cat file_list.dat
$TMP_DIR/file1.txt
$TMP_DIR_2/file2.txt
---------------------------
-> cat... (6 Replies)
Discussion started by: barath
6 Replies
9. Shell Programming and Scripting
Hi.
How do I achieve this
sh /EDWH-DMT02/script/MISC/exec_sql.sh "@/EDWH-DMT02/script/others/CSM_CKC/Complete_List.sql ${file_name}" Complete_List.txt
The /EDWH-DMT02/script/MISC/exec_sql.sh has two parameters and it's working fine with this
sh /EDWH-DMT02/script/MISC/exec_sql.sh... (7 Replies)
Discussion started by: aimy
7 Replies
10. UNIX for Dummies Questions & Answers
Any good way to check if code has the required output
# /sbin/sysctl net.ipv4.icmp_echo_ignore_broadcasts
net.ipv4.icmp_echo_ignore_broadcasts = 1
/sbin/sysctl net.ipv4.icmp_echo_ignore_broadcasts | grep "= 1"
net.ipv4.icmp_echo_ignore_broadcasts = 1
What I can think of is above, and it... (16 Replies)
Discussion started by: alvinoo
16 Replies