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.

I am writing notes as I prepare a system so I have something to follow if/when I need to prepare another system. Also I am hoping to use these notes and implement into a puppet configuration at some point.

I am trying to write multi-line bash commands, but when I copy and paste from my IDE (aptana) into the terminal, I get weird behavior and the commands never execute, even though when I step back in history the multi-line command looks like I entered it manually.

My question is, how can I save the commands in a multi-line format so I can quickly copy and paste into the terminal?

Example:

$ "mkdir -p /var/log/php && \
 chown -R apache /var/log/php && \ 
 chgrp -R webdev /var/log/php && \
 chmod -R 775 /var/log/php && \ 
 touch /var/log/php/oops.log"

touch /var/log/php/oops.log: No such file or directory
share|improve this question
add comment

3 Answers

up vote 2 down vote accepted

Bash control operators (such as &&) do NOT require a " \" to concatenate lines together. You also do not need to quote your script. The re-factored version would be:

mkdir -p /var/log/php && 
/bin/chown -R apache /var/log/php &&  
/bin/chgrp -R webdev /var/log/php && 
/bin/chmod -R 775 /var/log/php &&  
touch /var/log/php/oops.log

Cutting and pasting that script in a shell should work.

share|improve this answer
    
Interesting, I thought I tried this combo, apparently not. Your solution worked. Thanks! –  Mike Purcell Dec 13 '11 at 1:50
add comment

You could use exec:

$ exec <<< "echo hello world"

BUT keep in mind, it will exit your current shell once done. You could address this by spawning a new shell:

$ bash -s <<< "echo hello world"

Also, you could make it a bash script. Example:

#!/bin/bash
mkdir -p /var/log/php
chown -R apache /var/log/php
chgrp -R webdev /var/log/php
chmod -R 775 /var/log/php
touch /var/log/php/oops.log

You could do something like:

$ cat >> ~/script.sh
#!/bin/bash
mkdir -p /var/log/php
chown -R apache /var/log/php
chgrp -R webdev /var/log/php
chmod -R 775 /var/log/php
touch /var/log/php/oops.log
<CTRL+D>
$ . ~/script.sh
share|improve this answer
    
Was considering that... Just wanted to see if it was possible to copy and paste straight into the terminal first. –  Mike Purcell Dec 13 '11 at 1:47
    
Ah, you could address the spawning by opening a new shell. Thanks @Pascal.Charest. –  Beaming Mel-Bin Dec 13 '11 at 2:22
add comment

You simply do the first four commands by doing...

$ install -o apache -g webdev -m 0755 -d /var/log/php

This will create a directory /var/log/php with owner apache group webdev and permission 0755.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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