ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
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.
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.
I'm still confused about the scp. Are you trying to copy files across a network?
This code
line=xxx
scp line.txt useer@server:/path/
Puts the string xxx into the environment variable line, then copies some file named line.txt over a network. If you want to write the command line to the file with each word on it's own line, that would be like this
Code:
while [ -n $1 ]
do
echo $1 >> file.txt
shift
done
This says, while there is a first argument, append it (on a new line) onto file.txt. Then forget the first argument, and shift all the other arguments over. So, if the command arguments where "This is some text"
Then
Well, actually I want to generate a .txt file by .sh.
I don't need to redirect I/O or using pipe. It should be simple, just generate a data.txt, which contains these two sentenses....
line=xxx
scp line.txt useer@server:/path/
I think your method is to read two lines, then saved into a txt file. That is advanced level for me right now Thanks!
Quote:
Originally Posted by PatrickNew
I'm still confused about the scp. Are you trying to copy files across a network?
This code
line=xxx
scp line.txt useer@server:/path/
Puts the string xxx into the environment variable line, then copies some file named line.txt over a network. If you want to write the command line to the file with each word on it's own line, that would be like this
Code:
while [ -n $1 ]
do
echo $1 >> file.txt
shift
done
This says, while there is a first argument, append it (on a new line) onto file.txt. Then forget the first argument, and shift all the other arguments over. So, if the command arguments where "This is some text"
Then
Good, glad it works. Also, bash is really quite an easy language to learn, and very powerful too, at least at a high level, you can do many things with just a few simple commands. It took me no more than 1 week to learn the basics, the rest you'll learn as you write more scripts.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.