-1

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?

user08
  • 21
  • 1
  • 1
  • 6
  • 2
    someone with so many points (some sort of admin) will come and say > you didnt add sample and output. :)) – Pro Coder Dec 28 '19 at 18:53
  • I'm sorry I didn't get it :) – user08 Dec 28 '19 at 18:54
  • Indeed, please edit your question provide a small sample input and the desired output for that sample input. – ikegami Dec 28 '19 at 19:15
  • not an admin but I'll play ... OP: take a look at [How to create a minimal, reproducible exampl](https://stackoverflow.com/help/minimal-reproducible-example); in particular, show a sample of the contents of your variable, what your script is (incorrectly) generating, and what you're trying to (correctly) generate – markp-fuso Dec 28 '19 at 19:15
  • Please see edited post – user08 Dec 28 '19 at 19:39
  • 1
    The listed commands will give the desired output (although there are better ways to do it) unless something unusual has been set. Did you change `IFS`? Going through the process of creating a minimal, reproducible example will probably reveal the cause. – Gordon Davisson Dec 28 '19 at 22:43

2 Answers2

1

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[@]}"
user1934428
  • 19,864
  • 7
  • 42
  • 87
0

The easiest way is to use echo command as:

...
process=$(echo [0-9]*)
...
kofemann
  • 4,217
  • 1
  • 34
  • 39