Hi,
I'm new to shell programming.
I have two variables a and b
a=val1
b=val2
could anyone kindly post the shell script to concatenate the values of variable a and b with an underscore(_) in between?
The final output should be val1_val2.
Hi,
I'm new to shell programming.
I have two variables a and b
a=val1
b=val2
could anyone kindly post the shell script to concatenate the values of variable a and b with an underscore(_) in between?
The final output should be val1_val2.
c="${a}_${b}"
echo "${c}"
$ c="${a}_${b}"
$ echo $c
val1_val2
There is some discripency in the result that I am getting in the below shell script.
I have a configuration file having data as
fileTest.conf:
----------------
file=abc
value=123
The Shell Script is:
------------------
ram=`grep 'file=' fileTest.conf | awk -F"=" '{print $2}'`
shyam=`grep 'value=' fileTest.conf | awk -F"=" '{print $2}'`
echo $ram
echo $shyam
c="${ram}_${shyam}"
echo "$c"
Output:
-------
abc
123
_123
The output I want is
abc
123
abc_123
Could someone please let me know what the problem is in the script and how should be the correct script look like?
There is nothing wrong with your script if you are using either ksh or bash.
What shell are you using?
i'm using bash
You have a "\n" in $ram and problem will be solved if you modify the first awk to be like below
awk -F"=" '{printf"%s",$2}'`
Ahmad, are you saying that the OP's script did not work for you? Strange, because it worked just fine for me using both bash and ksh.
The script is sound.
You probably have a strange characters in the parameter file.
Try this sed to see what is in the parameter file.
sed -n l fileTest.conf
file=abc$
value=123$