I'm working in Bash using this nested shuf command to get an alphanumeric string of variable length:

shuf -erz -n $(shuf -e -n 1 {0..5})  {A..Z} {a..z} {0..9}

Current output:

This outputs the alphanumeric string on a new line in front of the shell prompt.

MyPrompt:$ shuf -erz -n $(shuf -e -n 1 {0..5})  {A..Z} {a..z} {0..9}

Desired output:

I'd like to have the output on it's own line.

MyPrompt:$ shuf -erz -n $(shuf -e -n 1 {0..5})  {A..Z} {a..z} {0..9}

Is there a way to alter the shuf command or append another standard Bash command after the shuf command to get the desired output? Other approaches are welcome too, but I'd like to make the change easy to add/remove.

I tried searching for previous answers, but I'm pretty new to Bash and I can't seem to identify the right terms to lead to helpful results. Likewise, I've experimented with my own approaches (mostly using echo and piping), but haven't had success there either.

2 Answers 2


I would probably solve that by appending ; echo to the command.

  • Thank you. That's exactly the sort of thing I was looking for.
    – LoopedLine
    Feb 14, 2022 at 20:27
  • 1
    If you want to preserve nonzero exit status of the command, of course, you'd want to && echo instead of ; echo.
    – MSmedberg
    Dec 6, 2022 at 19:57

In case you just want to have your output on a seperate line use paste:

paste <(shuf -erz -n $(shuf -e -n 1 {0..5})  {A..Z} {a..z} {0..9})
  • Thank you. In terms of output, that achieves my objective. In order to make it easy to add and remove, is there a way to utilize paste that puts it at the end of the command?
    – LoopedLine
    Feb 14, 2022 at 17:06

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .