LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices

Reply
 
LinkBack Search this Thread
Old 03-15-2005, 03:10 AM   #1
acidjuice
Member
 
Registered: Jan 2005
Location: a tiny spot on the iceberg
Distribution: Slackware 10.1 (dropline 2.10, kernel 2.6.11.6)
Posts: 320

Rep: Reputation: 30
create text file from terminal


hello all,

i'd like to know if it's possible to create a script from a terminal command.

for instance, i'd like to have a script mycopy.sh that copy files:
Code:
cp myfile destfile
cp my2file my2desfile
...
but i would like to create this script FROM the terminal using coreutils, something like (this of course WON'T do )
Code:
cp myfile destfile && cp my2file my2desfile >> mycopy.sh
is this possible?

thanks,

aj.
 
Old 03-15-2005, 03:19 AM   #2
Yalla-One
Member
 
Registered: Oct 2004
Location: Norway
Distribution: Slackware, CentOS
Posts: 635

Rep: Reputation: 35
If I understand you correct you want to create a script from the commandline.

Could these commands be what you're looking for?

## Create an empty file mycopy.sh
touch mycopy.sh

##Tell the script which shell to use:
echo "#!/bin/sh" >> mycopy.sh

##Add content to the script
echo "cp myfile destfile" >> mycopy.sh
echo "cp my2file my2desfile" >>mycopy.sh

##when done, set permissions
chmod 755 mycopy.sh

Done!

(The >> appends instead of over-writing)
 
Old 03-15-2005, 03:19 AM   #3
gerardt
Member
 
Registered: Feb 2005
Location: South Africa
Distribution: SuSE
Posts: 60

Rep: Reputation: 15
echo "cp myfile destfile && cp my2file my2desfile" >> myscript.sh

Is that what you are looking for?
 
Old 03-15-2005, 03:22 AM   #4
gerardt
Member
 
Registered: Feb 2005
Location: South Africa
Distribution: SuSE
Posts: 60

Rep: Reputation: 15
Yalla-One : Much more thorough approach. Good stuff
 
Old 03-15-2005, 03:22 AM   #5
acidjuice
Member
 
Registered: Jan 2005
Location: a tiny spot on the iceberg
Distribution: Slackware 10.1 (dropline 2.10, kernel 2.6.11.6)
Posts: 320

Original Poster
Rep: Reputation: 30
Code:
echo 'cp myfile destfile' >> mycopy.sh
echo 'cp my2file my2desfile' >>mycopy.sh
this was exactly what is was looking for!

it looks so stupid now

thank you SO much guys for this fast reply...

aj.

Last edited by acidjuice; 03-15-2005 at 06:47 AM.
 
Old 03-15-2005, 07:25 AM   #6
theYinYeti
Senior Member
 
Registered: Jul 2004
Location: France
Distribution: Arch Linux
Posts: 1,897

Rep: Reputation: 61
Also nicely working:
Code:
$ cat >myscript.sh <<-"THEEND"
#!/bin/bash

cp file1 dest/
cp file2 dest/
THEEND
$
Yves.
 
Old 07-14-2010, 05:43 PM   #7
jackonapsp
LQ Newbie
 
Registered: Jul 2010
Location: /home
Distribution: tty linux
Posts: 17

Rep: Reputation: 0
Unhappy My one doesn't work

My one doesn't seam to be working

echo 'echo hello' >> mycopy.sh
cannot create mycopy.sh: No such file or directory


please note that this is through telnet on my linux router specs down there
BusyBox v0.61.pre (2007.03.15-06:14+0000) Built-in shell (ash)
 
Old 07-14-2010, 06:58 PM   #8
Andrew Benton
Senior Member
 
Registered: Aug 2003
Location: Birkenhead/Britain
Distribution: Linux From Scratch
Posts: 2,073

Rep: Reputation: 64
Quote:
Originally Posted by Yalla-One View Post
##Tell the script which shell to use:
echo "#!/bin/sh" >> mycopy.sh
I'm pretty sure that if you did that at the command line (bash shell) you'd get
Quote:
andy:~$ echo "#!/bin/sh" >> mycopy.sh
bash: !/bin/sh": event not found
Quote:
Originally Posted by jackonapsp View Post
My one doesn't seam to be working

echo 'echo hello' >> mycopy.sh
cannot create mycopy.sh: No such file or directory


please note that this is through telnet on my linux router specs down there
BusyBox v0.61.pre (2007.03.15-06:14+0000) Built-in shell (ash)
Is that a read only file system?
 
Old 09-03-2010, 03:46 AM   #9
jackonapsp
LQ Newbie
 
Registered: Jul 2010
Location: /home
Distribution: tty linux
Posts: 17

Rep: Reputation: 0
Red face

Oh i feel so stupid it's a read only system sorry
 
  


Reply


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
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Which light text editor can copy text from file and paste in browser? davidas Linux - Software 9 03-06-2006 11:28 AM
How to find and change a specific text in a text file by using shell script Bassam Programming 1 07-18-2005 07:15 PM
Create a text file using Bash Boffy Programming 5 03-14-2005 09:06 PM
Linux shell command for makefile.in to create a text file and write to it alix123 Programming 8 01-07-2005 08:18 AM
Create text file with a script zael Programming 3 06-02-2004 03:27 AM


All times are GMT -5. The time now is 12:51 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration