1

In my shell script, I have using below code:

RECORD=`ps -ef | grep sysProj | cut -d" " -f1,2` echo $RECORD 

on executing this, its printing

45646654 28770 45646654 32021 45646654 32176 

but when I don't save command output in variable and executing as below:

ps -ef | grep sysProj | cut -d" " -f1,2 

the output is:

45646654 28770 45646654 32021 45646654 32176 

Why saving the command output in varible is suppressing new line character. Also, how can I retain it?

2

1 Answer 1

4

Just enclose the variable within double quotes to avoid word splitting:

echo "$RECORD" 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.