Solved Command Line Special Character Handling

I was trying to help a user here and I found I could not use the command I intended.
echo exec $1 > .xinitrc
In the file it dropped of the $1 so I tried double quotes to no avail
echo "exec $1" > .xinitrc
What can I use here for proper redirect? I am guessing $1 is an asci thing?
 
What are you trying to do? Both exec and the $1 are probably not going to do what was intended.

Let's instead call the variable $x so the shell does not replace it, and not use exec, which does not just execute the command given but replaces the running shell with it.
Code:
echo `$x` >> .xinitrc
In general, that seems like a weird way to write that file, since few commands are going to create the correct contents to go in there.
 
Rookie trys with a strikeout:
root@Dell:~ # echo "[exec $1]" >> .xinitrc
root@Dell:~ # echo ( "exec $1" ) >> .xinitrc
Badly placed ()'s.
root@Dell:~ # echo {"exec $1"} >> .xinitrc

Shoot dang- RTFM
https://www.freebsd.org/doc/handbook/shells.html

Code:
root@Dell:~ # echo exec \$1 > .xinitrc
root@Dell:~ # cat .xinitrc
exec $1
This will work too:
Code:
echo 'exec $1' > .xinitrc
The single quotes won't interpret any $ variables but takes the $ literally.

Code:
FOO='something'
echo "$FOO"
echo '$FOO'
 
Back
Top