hi guys
wht is the difference between these two command in bash shell scripting
$var1=world!
$echo hello $var1
$echo "hello $var1"
$ var1='World!'
$ echo Hello $var1
Hello World!
$ echo Hello $var1
Hello World!
$ echo "Hello $var1"
Hello World!
$ echo "Hello $var1"
Hello World!
$
The quotes tell the shell to interpret Hello and the substitution of var1 as one parameter (including the space(s)), instead of two parameters.
thanks for reply
i am little bit confused...
can u tell me clearly.....
plzzzzz
The shell uses the space character ' ' as seperator for arguments passed to commands.
The line
echo Hello World
is parsed by the shell like this:
- Command: echo
- First argument: Hello
- Second argument: World
The line
echo "Hello World"
is parsed by the shell like this:
- Command: echo
- First argument: Hello World
vow great...
now i understood ....very clearly
thank you ...thank you very much....
In addition to what has been already posted, the version in quotes will preserve multiple space characters.
Try with say three spaces between "hello" and "world":
echo "hello world"
hello world
echo hello world
hello world
Actually both " " and ' ' turns off the special meanings of the meta characters, except that " " doesn't do that for \ $ ' and ".
But from the number of arguments interpretation point of view, at least in KornShell they function the same way.
#!/bin/ksh
VALUE1="hello world"
VALUE2='hello world'
for ITERATOR in $VALUE1
do
print "$ITERATOR"
done
for ITERATOR in $VALUE2
do
print "$ITERATOR"
done
Both of them will print
hello
world
In each loop there is two arguments (two values for $ITERATOR)
But as soon as you change the loop to
for ITERATOR in "$VALUE1"
it's only one iteration again
Yes, you're right, I didn't know that, thanks for this remark