Is there a way to concatenate two strings, where the first string is "-n" and there is a space between the "-n" and the second string? Below are some examples of what I tried.
#!/bin/sh
var1=test
#working without dashes:
var2="n $var1"
echo $var2
var2=n" "$var1
echo $var2
var2="n "$var1
echo $var2
#not working with dashes:
var2="-n $var1"
echo $var2
var2=-n" "$var1
echo $var2
var2="-n "$var1
echo $var2
#not working with escaped dashes:
var2="\-n $var1"
echo $var2
var2=\-n" "$var1
echo $var2
var2="\-n "$var1
echo $var2
hi..
"-" is a shell metacharacter . So it needs strong quoting.
trying using single quotes '-n' or escape is using '\'.
Hope that works for you .
Regards.