I run the following commands:
cd /proc
process=$(ls | egrep '[0-9]')
echo $process
I get the following output:
1
108
109
8130
However, I want to have the following output:
1 108 109 8130
How can I do that?
I run the following commands:
cd /proc
process=$(ls | egrep '[0-9]')
echo $process
I get the following output:
1
108
109
8130
However, I want to have the following output:
1 108 109 8130
How can I do that?
Since your variable process
is only be used in the echo
, I would simplify your script to
cd /proc
echo *[0-9]*
If you really need the process names for postprocessing in a later step, I would store them in an array:
processes=(*[0-9]*)
With this approach, you can display them in a single line using
echo "${processes[@]}"
The easiest way is to use echo
command as:
...
process=$(echo [0-9]*)
...