Isaiah
Isaiah

Reputation: 2023

Generating a bash script with echo, problem with shebang line

I want to explain to some friends how to add multikey support to their linux systems at bootup but first I need them to make a bash script. I want to make a simple command for them to copy and paste and I'm testing out this command I made but it keeps throwing an error. Only when I add the shebang line which, well is important.

$ sudo echo -e "#!/bin/bash \nxmodmap \"keysym Alt_R = Multi_key\"" > /etc.init.d/multikey.sh

Any easy way to echo a shebang line?

Upvotes: 20

Views: 9807

Answers (2)

hmontoliu
hmontoliu

Reputation: 4019

If you want to impress your friends use here documents not echo strings :-)

~$ cat << EOF > /etc/init.d/multikey.sh
> #!/bin/bash          
> xmodmap "keysym Alt_R = Multi_key"
> EOF

Upvotes: 17

Ignacio Vazquez-Abrams
Ignacio Vazquez-Abrams

Reputation: 798626

Use the other quotes.

sudo echo -e '#!/bin/bash\nxmodmap "keysym Alt_R = Multi_key"'

Upvotes: 39

Related Questions