LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 10-17-2016, 10:46 AM   #1
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (15 current), Slack15, Ubuntu studio, MX Linux, FreeBSD 13.1, WIn10
Posts: 10,342

Rep: Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242
adding text to file using echo


I was trying to be lazy about this and just create a bash script right off of the command line then adding what I needed inside of it by doing this. but BASH keeps thinking i am trying to run one I think.
instead of just opening up a text editor and do this, but because BASH is doing what it is doing it raised a question . how do I do this without having to open up a text editor.

add the line #!/bin/bash

Code:
userx@Voided.1 & ~ >>touch playmusic

userx@Voided.1 & ~ >> $echo "#!/bin/bash" > playmusic 
bash: !/bin/bash: event not found
userx@Voided.1 & ~ >> $hi="#!/bin/bash"
bash: !/bin/bash: event not found
userx@Voided.1 & ~ >> $hi="hi"
userx@Voided.1 & ~ >> $echo hi > playmusic
userx@Voided.1 & ~ >> $cat playmusic
hi
userx@Voided.1 & ~ >> $hi="/#!/bin/bash"
bash: !/bin/bash: event not found

userx@Voided.1 & ~ >> $hi="\#!/bin/bash"
bash: !/bin/bash: event not found
do you understand what is going on here? Bash will not allow me to echo its directive into a file.

how do I do this?

Last edited by BW-userx; 10-17-2016 at 10:52 AM.
 
Old 10-17-2016, 10:49 AM   #2
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,598
Blog Entries: 4

Rep: Reputation: 3894Reputation: 3894Reputation: 3894Reputation: 3894Reputation: 3894Reputation: 3894Reputation: 3894Reputation: 3894Reputation: 3894Reputation: 3894Reputation: 3894
It's about the quotes and the exclamation mark:

http://mywiki.wooledge.org/Quotes
 
Old 10-17-2016, 10:57 AM   #3
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (15 current), Slack15, Ubuntu studio, MX Linux, FreeBSD 13.1, WIn10
Posts: 10,342

Original Poster
Rep: Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242
Quote:
Originally Posted by Turbocapitalist View Post
It's about the quotes and the exclamation mark:

http://mywiki.wooledge.org/Quotes
Code:
userx@Voided.1 & ~ >> $touch shitfile
userx@Voided.1 & ~ >> $echo '#!/bin/bash' > shitfile
userx@Voided.1 & ~ >> $cat shitfile
#!/bin/bash
thanks ! got it.
 
Old 10-17-2016, 11:21 AM   #4
szboardstretcher
Senior Member
 
Registered: Aug 2006
Location: Detroit, MI
Distribution: GNU/Linux systemd
Posts: 4,278

Rep: Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694
Escaping characters would be good to know as well:

Code:
echo \#\!/bin/bash > test
cat test
#!/bin/bash
 
Old 10-17-2016, 01:13 PM   #5
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (15 current), Slack15, Ubuntu studio, MX Linux, FreeBSD 13.1, WIn10
Posts: 10,342

Original Poster
Rep: Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242
Quote:
Originally Posted by szboardstretcher View Post
Escaping characters would be good to know as well:

Code:
echo \#\!/bin/bash > test
cat test
#!/bin/bash
oh I just needed one more escape, and that'd a would have worked too. again more then one way to skin a cat.
as I tried it hitting that wrong one / first time then the other one \ the next time, but only placing in one of them.

if you go back and look you'll see.


k ...
 
  


Reply

Tags
bash, cat, scripts


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
echo text into the beginning of a specific line of a existing file RandyH9 Programming 3 04-13-2014 03:36 PM
[SOLVED] Problem echoing text to shell file with quotes in the middle of the echo command AntBla Linux - Newbie 2 02-16-2014 06:56 AM
[SOLVED] echo text to a specific line in an existing file Jammyzx Programming 6 10-12-2011 01:17 AM
Adding lines of text to beginning of a text file BillKat Programming 2 01-19-2009 11:40 AM
echo text from an apache served web page to a fifo file? johnson_steve Linux - Server 2 07-25-2008 11:24 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 09:57 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration