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 |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
|
10-17-2016, 10:46 AM
|
#1
|
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
|
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.
|
|
|
10-17-2016, 10:49 AM
|
#2
|
LQ Guru
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,598
|
It's about the quotes and the exclamation mark:
http://mywiki.wooledge.org/Quotes
|
|
|
10-17-2016, 10:57 AM
|
#3
|
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
|
Quote:
Originally Posted by Turbocapitalist
|
Code:
userx@Voided.1 & ~ >> $touch shitfile
userx@Voided.1 & ~ >> $echo '#!/bin/bash' > shitfile
userx@Voided.1 & ~ >> $cat shitfile
#!/bin/bash
thanks ! got it.
|
|
|
10-17-2016, 11:21 AM
|
#4
|
Senior Member
Registered: Aug 2006
Location: Detroit, MI
Distribution: GNU/Linux systemd
Posts: 4,278
|
Escaping characters would be good to know as well:
Code:
echo \#\!/bin/bash > test
cat test
#!/bin/bash
|
|
|
10-17-2016, 01:13 PM
|
#5
|
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
|
Quote:
Originally Posted by szboardstretcher
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 ...
|
|
|
All times are GMT -5. The time now is 09:57 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|