Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

How do I create a file with the contents "echo hello world" with the name hello.sh in one line?

share|improve this question

closed as off topic by Kyle Smith, womble, Lucas Kauffman, Khaled, Wesley Apr 6 '12 at 1:38

Questions on Server Fault are expected to relate to professional server, networking, or related infrastructure administration within the scope defined by the community. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about reopening questions here.If this question can be reworded to fit the rules in the help center, please edit the question.

add comment

2 Answers

up vote 3 down vote accepted

Just use echo and direct the output to the file:

echo "echo hello world" > hello.sh
share|improve this answer
add comment

In a terminal, you could:

  • Use echo to place a line in a file, like echo 'echo hello world' > hello.sh.
  • Use vi to edit hello.sh (vi hello.sh). Once in the editor you would use i to enter Insert mode, type the contents you wish the file to have, then press Esc to enter Normal mode. In Normal mode, you would use :wq to save the file and exit vi.
  • Use nano to edit the file (nano hello.sh). nano is a simpler editor without "modes". You simply type the contents you want and use Ctrl + O to save the file, and Ctrl + X to exit nano.

If you have access to a graphical environment, there are many text editors you can use and they depend mainly on the desktop environment provided by your distribution.

  • In GNOME 2, you could use gedit. It's typically under Applications > Accessories > Text Editor.
  • In GNOME 3, you would also use gedit, but you would find it by pressing Super (Also known as the Windows Key) and scrolling through the icons (or beginning to type "Text Editor").
  • In KDE, you could use kate. It's found in the main menu under Accessories.
share|improve this answer
    
thxs but was looking for a one-liner –  DD. Apr 4 '12 at 10:29
    
My first bullet point is a one-liner. –  Kyle Smith Apr 4 '12 at 10:31
add comment

Not the answer you're looking for? Browse other questions tagged or ask your own question.