When runing the command:
The echo command "I am Here" will appear only based on the second value, in other words only if the there is no file name "table" regardless if there isn't a file name "chair".. Why is that ?
B.What exactly did we done here ?. We sent an argument to a file containing shell commands ?
Did you notice the $2 that I marked in red in your script? Do you see that the test is looking for a file named by the 2nd command-line argument passed to your script?
What happens if you change the $2 to $1 and rerun your script at times when there is a file named chair and at times when there is not a file named chair?
What do you think might happen if you changed the line in your script that is currently:
to:
or to:
? Note that I added double quotes around each parameter expansion. With the files named in your example and the default characters specified in "$IFS", it doesn't matter. But you should always write you code to protect yourself in case an argument is passed to your script that contains <space>s, <tab>s, or <newline>s.
Last edited by rbatte1; 04-11-2018 at 01:16 PM..
Reason: Spelling
This User Gave Thanks to Don Cragun For This Post:
Hi,
I am new to Unix, and I am trying to append a line of argument into a current file. I need this line to be inserted into the very top of the file. Does anyone know how this is done?
For example, I am trying: echo "insert to top" >> filename. This inserts the line at the bottom of the... (7 Replies)
when directing some text into a file can you choose where it goes like the top of the file (which is text aswell) or the middle??
if so how - especially would like to know how to do so in vi (text editor)
If i were to enter an argument ($1) into a another argument ($2)
would it would be... (6 Replies)
Hi Gurus,
I am having an requirement. i have to read a list file which contains file names and send mail to different users based on the files in the list file.
eg. if file a.txt exists then send a mail to a@a.com
simillary for b.txt,c.txt etc.
Thanks for your help,
Nimu (6 Replies)
Can someone please help me with this SHELL script?
I need to create a script that gets a positive number n as an argument. The script must calculate the factorial of its argument. In other words, it must calculate n!=1x2x3x...xn. Note that 0!=1.
Here is a start but I have no clue how to... (3 Replies)
I am trying to delete lines from a file with the sed command.
I have two files. File a.txt 200,000 records. Here is a sample of the file.
File a.txt
2401ABC0212345678 plus 250 characters of other data
2401ABC0212345678 plus 250 characters of other data
2402ABC0212345678 plus... (3 Replies)
If ($argv == “-debug”) then
Echo “in loop”
Endif
But this is not working. If I modify this code and remove “-“, then it works.
Similarly I am getting problem using grep command also
Grep “-debug” Filename
Can someone please help me on how to resolve these... (1 Reply)
Hello,
Is there any method thorugh which script can take argument if pass otherwise if argument doesn't pass then it takes the argument from the configuration file
i.e I am workiing on a script which will run through crontab and the script will
chekout the code ,zip and copy to the... (3 Replies)
Hi All,
I am running the script
VBoxManage list vms |sed 's/"//g' | cut -d " " -f1 > har1out.mytxt
result=`cat har1out.mytxt | grep $1'
echo $result
echo $1
{
if
then
echo pass
else
echo fail
fi (2 Replies)