You described yourself as "done some C++" in your original thread and i suppose it is the difference between shell scripting and high level languages, which makes this hard to understand for you:
A single line in a HLL is read by a parser, then compiled to object code and finally this object code is executed. All the interpretation of the code is done at compile time and all the execution is done at run time. This is fundamentally different with shell scripting.
The big difference is that the interpretation part and the execution part takes place at the same time and in fact is a tightly interwoven process. The following, for instance, has no counterpart in any high-level language:
In line one a variable is created and filled with a certain content. In the second line this variable is executed as command! Well, in fact not the variable is executed, but the command is: when the shell has to execute this line the first step is to "expand" all the variables, which means to literally replace them with their values. Only then the resulting line is executed.
This makes shell code very versatile (it was created with the purpose of "being able to quickly whip together something" in mind).
This evaluation process does not stop at variables. You sure have done something like this already:
The asterisk is also interpreted by the shell. It is replaced ("expanded") to the list of files matching the pattern (in this case "anything ending in 'txt'").
Consider the following line:
This is what the shell will do:
(i supposed to have the three files "a.file", "b.file" and "c.file" in this directory)
The only way to prevent the shell from doing this expansion is to quote: use double quotes to prevent it from expanding wildcards (which is why it hasn't expanded the asterisk in line 1 already) and single quotes to prevent expansion of variables:
Hi List,
Is it possible to pass one argument to a shell program
eg) there is a shell program abc which takes one arguments
abc one
Due to some reasons I pass
abc one two
Now one,two must be considered as "one" argument to the shell programs. Any suggestions,hints are welcome.
... (3 Replies)
Hi All,
I need some help/ideas in coming up with a shell script.
Basically, the script should install 1 or 2 or 3 packages based on the input arguments.
For example, if I type in pkgscript.sh a1 a2 a3, it should install all the 3 scripts and pkgscript.sh a1 should install only a1.
If a... (3 Replies)
Hi
How to call a shell scripting through a Perl scripting? Actually I need some value from Shell scripting and passes in the Perl scripting. So how can i do this? (2 Replies)
Hello,
I have to make a shell script doing that :
the program tests if there is an argument, if there is it checks whether this is a directory or not, If it is it opens it.
for any .c file in the directory it prints 2 lines in the screen :
the dependence line of the .o and compiler commend... (1 Reply)
Hi,
I have a shell script, when run it i get a prompt to enter arguments say 1 for doing my next task otherwise q for quit.
What I am trying to do is run the shell script with the argument passed in however it does not seem to work.
This is what I did
./test.sh 1
Instead it printed the line... (6 Replies)
Hi All,
I am using the script for creating local queue and passing the arguments while running the script as below
n=0
while
do
e=`expr $n + 3`
echo 'DEFINE QL('$e') MAXDEPTH('$6') MAXMSGL('$7') DEFPSIST('$8') '$9'' | /apps/mqm_opt/bin/runmqsc $2
n=`expr $n + 1`
done
Running the... (5 Replies)
This is the script I already have but I have problems with two arguments
the first argument -t , I want to count 200 by the last digit of the IP address for example when I run the script ./ping.sh -t 17, the output would be192.168.0.217 is upThe second arguments --up won't work. Could anybody... (1 Reply)
I at the moment, making a simple bash script, capable of setting up an workspace for me, so i don't have to do it manually.. Problem is though i can't seem to provide the bash script any argument, without running into my error checks, checking for input...
Here is the code:
#!/bin/bash... (7 Replies)