I need to know how to concatenate variables in Debian. I am making a interactive script where it ask the user for info to add a user I pull the first letter from the first middle and last name into individual variables now i want to put them all in one variable so i can put it into useradd command
This is what happening
v1= echo $firstname | cut -b 1
v2= echo $lastname | cut -b 1
v3= echo $middlename | cut -b 1
uname= $v1 $v2 $3
echo $uname
output:
a
d
s
I need the output to look like this
output:
ads
Thanks in advance
I need to know how to concatenate variables in Debian. I am making a interactive script where it ask the user for info to add a user I pull the first letter from the first middle and last name into individual variables now i want to put them all in one variable so i can put it into useradd command
This is what happening
v1= echo $firstname | cut -b 1
v2= echo $lastname | cut -b 1
v3= echo $middlename | cut -b 1
uname= $v1 $v2 $3
echo $uname
output:
a
d
s
I need the output to look like this
output:
ads
Thanks in advance
Please use code tags, please do not double post, and consider reading the rules of the forum.
Your shell is bash, this gives the result of the first character from each of three variables concatenated
result=${firstname,0,1}${middlename,0,1}${lastname,0,1}
If you want to do it like in your own example your left out a couple of things and there were too many spaces:
v1=$(echo "$firstname" | cut -b 1)
v2=$(echo "$lastname" | cut -b 1)
v3=$(echo "$middlename" | cut -b 1)
uname=$v1$v2$v3
echo "$uname"
Jim's example should have : instead of , then it should work