Preserving newlines when writing loops on the command line in bash


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Preserving newlines when writing loops on the command line in bash
# 1  
Old 03-02-2011
Preserving newlines when writing loops on the command line in bash

Dear All,

I have a question that's been difficult to get an answer to.

I often write command line loops, e.g. find files, print name, grep for term, apply sed, etc

I use both zsh and bash.

When I write a loop e.g.

Code:
for line in `more myfile.txt`
> do
> echo $line
> done

but then cycle back through the history, in Bash it is re-formatted as:

Code:
for line in `more myfile.txt`; do echo $line; done

In zsh, it is not re-formatted, it is displayed on separate lines, just as I input it.

I much prefer it being displayed line by line (i.e. the zsh way) rather than on a single line with semicolon separation.

Do you know if/how I can force bash to represent this line by line?

Thanks alot

Regards

JohnK1
# 2  
Old 03-02-2011
Quote:
Originally Posted by bash man page

lithist

If set, and the cmdhist option is enabled, multi-line commands are saved to the history with embedded newlines rather than using semicolon separators where possible.
Regards,
Alister
# 3  
Old 03-02-2011
Alister,

That's great, thanks very much.

Regards

JohnK1
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to run several bash commands put in bash command line?

How to run several bash commands put in bash command line without needing and requiring a script file. Because I'm actually a windows guy and new here so for illustration is sort of : $ bash "echo ${PATH} & echo have a nice day!" will do output, for example:... (4 Replies)
Discussion started by: abdulbadii
4 Replies

2. Shell Programming and Scripting

sed a multiple line pattern that has newlines followed by text and r

Here is the text that I was to run sed on. In this text I want to insert a semi colon ';' before 'select a13.STORE_TYPE STORE_TYPE,' and after 'from ZZMR00 pa11' Input text: insert into ZZMQ01 select pa11.STATE_NBR STATE_NBR, pa11.STORE_TYPE STORE_TYPE, ... (9 Replies)
Discussion started by: v_vineeta11
9 Replies

3. Shell Programming and Scripting

Bash - Loading a command's output line by line into an array

I have been trying this a lot of different ways and haven't found too much online. Here's what I've got so far: j=0 declare -a first zero=(`cat $tmpfile`) for i in "${zero}" do command $i >> "${first}" ... (4 Replies)
Discussion started by: Azrael
4 Replies

4. Shell Programming and Scripting

'for LINE in $(cat file)' breaking at spaces, not just newlines

Hello. I'm making a (hopefully) simple shell script xml parser that outputs a file I can grep for information. I am writing it because I have yet to find a command line utility that can do this. If you know of one, please just stop now and tell me about it. Even better would be one I can input... (10 Replies)
Discussion started by: natedawg1013
10 Replies

5. UNIX for Dummies Questions & Answers

Running set options from the command line and bash command

I'm reading about debugging aids in bash and have come across the set command. It says in my little book that an addition to typing set you can also use them "on the command line when running a script..." and it lists this in a small table: set -o option Command Line... (5 Replies)
Discussion started by: Straitsfan
5 Replies

6. Homework & Coursework Questions

Bash if and loops help

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: Your shell script should continue to execute until the user selects option 4 2. Relevant commands, code,... (2 Replies)
Discussion started by: boyboy1212
2 Replies

7. Shell Programming and Scripting

Accepting filename as command line param and writing to it

Hi, Is it possible to accept a filename as command line parameter and then write to that file using command redirection? i tried the below script. outputfile=`echo $1` echo "Writing to file" > 'echo $outputfile' exit $returncode but it isnt working. is there any other way to... (9 Replies)
Discussion started by: silas.john
9 Replies

8. Shell Programming and Scripting

Bash scripting question re: newlines

I'm writing a bash script to search the contents of a postfix log. To keep the script's output readable (since multiple lines from the log file need to be echo'ed) I am setting the IFS variable to an empty string so that the line breaks in my grep results are preserved. I am storing the results... (4 Replies)
Discussion started by: retrovertigo
4 Replies

9. UNIX for Dummies Questions & Answers

Preserving space during command substitution

Hi all, I am caught up in a problem .... tried all possible ways i knew .. but ended up in big zero ... ;-( I have a file as below .. $ cat siv.txt 1234567890BF00522000095ibsadministrator@ae.ge.com ibsadministrator@ae.ge.com Note the spaces in between .... I am... (1 Reply)
Discussion started by: Sabari Nath S
1 Replies
Login or Register to Ask a Question