Simple question about linebreaks


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Simple question about linebreaks
# 1  
Old 08-30-2006
Simple question about linebreaks

Is there a way, when writing a script, so that although you may go to the next line in the script, it will not be interpreted that way. This could be useful using su (the case where I have the problem) so like ive got something like this:

su - user "-c command1; command2; command3; command4"

And for readability purposes you wanted to break it up into 4 lines so like:

su -user "-c command1;
command2;
command3;
command4"

How could I make this work?

Thanks
# 2  
Old 08-30-2006
Code:
$ su - root -c "echo foo
> echo bar
> echo something else
> "

Cheers
ZB
# 3  
Old 08-31-2006
Use the line continue option....
eg
#su - user -c "command1\
command2\
command3\
command4"
Pad it out if in a shell script so it looks neater....
# 4  
Old 08-31-2006
Quote:
Originally Posted by Andrek
Use the line continue option....
eg
#su - user -c "command1\
command2\
command3\
command4"
Pad it out if in a shell script so it looks neater....
Incorrect. The line continuation character is not what you want here.

Code:
$ su - root -c "echo foo\
> echo bar\
> echo something else"
Password:
fooecho barecho something else

Cheers
ZB
# 5  
Old 08-31-2006
Slight syntax error for got the ";"
#su - user -c "command1;\
command2;\
command3;\
command4"

But it works
# 6  
Old 08-31-2006
Dont understand the echos...I tried it and all it did was printed string versions of the commands, instead of running the commands..the backslash solution, however, worked beautifully
# 7  
Old 08-31-2006
The echos were just example commands.......
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Simple question

Sorry for stupid question, but why this script gives that output? $ awk 'BEGIN { well=56789; print 1234$well }' 1234 I expected 123456789 (9 Replies)
Discussion started by: silyin
9 Replies

2. Red Hat

Syslog.conf: looking for a simple answer on a simple question

Cheers! In /etc/syslog.conf, if an error type is not specified, is it logged anywhere (most preferable is it logged to /var/log/messages) or not? To be more precise I am interested in error and critical level messages. At default these errors are not specified in syslog.conf, and I need to... (6 Replies)
Discussion started by: dr1zzt3r
6 Replies

3. Shell Programming and Scripting

sed Linebreaks

Hi All, I have a linebreak in mid text \n and would like to remove this. I only want the \n at the end of the line. Any suggetions on how I would get this to work? I had: cat $LOGFILE| sed '{ /\n\ /\n$\! s\n\g ... (1 Reply)
Discussion started by: SalientAnimal
1 Replies

4. UNIX for Dummies Questions & Answers

simple(?) if/else question

Hello, I have a quick question that is not related to homework in any way shape or form (in case anyone wanted to know). My question is thus: I have a file "temp" that has the two values say "5" and "3" (separated by a white space). Now, I want to simply write an if-else statement that reads... (10 Replies)
Discussion started by: astropi
10 Replies

5. UNIX for Dummies Questions & Answers

Simple question

I had a script in solaris wich i read data, for example: Number 1: _ and the cursor use to be in '_' place because in the code of the script i write: echo "Number 1:\c" but i copy the script to a linux and the cursor 'jump' to the begining of the next line like: Number 1:... (2 Replies)
Discussion started by: lestat_ecuador
2 Replies

6. Programming

Simple C question... Hopefully it's simple

Hello. I'm a complete newbie to C programming. I have a C program that wasn't written by me where I need to write some wrappers around it to automate and make it easier for a client to use. The problem is that the program accepts standard input to control the program... I'm hoping to find a simple... (6 Replies)
Discussion started by: Xeed
6 Replies

7. UNIX for Dummies Questions & Answers

simple if then fi question

i'm trying to make a script that prints the name of the script for any command line parameter, here is what i have, and get `]]' unexpected: what am i doing wrong? (3 Replies)
Discussion started by: tefflox
3 Replies

8. UNIX for Dummies Questions & Answers

Ok simple question for simple knowledge...

Ok what is BSD exactly? I know its a type of open source but what is it exactly? (1 Reply)
Discussion started by: Corrail
1 Replies

9. UNIX for Dummies Questions & Answers

Hopefully simple question

When i type cd etc/shadow it says that file or directory doesnt exist? Is there a way to show this or am i typing something wrong? :confused: (6 Replies)
Discussion started by: Corrail
6 Replies

10. UNIX for Dummies Questions & Answers

Simple question

I am taking an intro to unix class and I can not figure out how to do part of the question. I am writing script to be exictued by a program in the tutoral. Question: Write every line containing the word ``delete'' produced by ``man mail'' into a file called ``delete''. Hint: What does using... (1 Reply)
Discussion started by: weathergirl
1 Replies
Login or Register to Ask a Question