Wednesday, December 26, 2012

Assign String/Number to variable

The given script is shown assign value/string into variable. one important thing is dont give space before and after equal (=) sign.

#!/bin/bash
a=23              # Simple case
echo $a
b=$a
echo $b

# Now, getting a little bit fancier (command substitution).
a=`echo Hello!`   # Assigns result of 'echo' command to 'a' ...
echo $a
a=`ls -l|tail -n 3`         # Assigns result of 'ls -l' command to 'a'
echo $a           # Unquoted, however, it removes tabs and newlines.
echo
echo "$a"         # The quoted variable preserves whitespace.


strVar="Hello"
echo "$strVar"

exit 0

Here
a=23                   --> value 23 is assigned into variable a
echo $a               --> used to display value at a (@a)
b=$a                  --> can assign variable to another variable
a=`echo Hello!`  --> can execute any shell command and assign the output into variable
strVar="Hello"    --> assign the string into variable

No comments:

Post a Comment

Item - Category Query

      SELECT      msi.segment1 AS Item_Code,       msi.DESCRIPTION AS Item_Desc,       mcs.CATEGORY_SET_NAME,       mck.CONCATENATED_SEGMEN...