0

Fairly new to Linux. I have a nixie clock that runs off of a Raspberry Pi. I would like to send a random sequence of six digits to it every so often to help prolong the life of the Nixie tubes.

There is a CLITool program I found on GitHub that lets me display any six digits using the command CLITool xxxxxx, where x is any digit 0-9. So I tried creating a bash file with the line shuf -zer -n6 {0..9}|CLITool.

The shuf command produces a random six digit string of numbers, but it does not seem to get piped to the CLITool. Like I mentioned, fairly new to Linux, so it could be something basic I am missing.

terdon
  • 234,489
  • 66
  • 447
  • 667
Joey29
  • 9
  • 1
  • Related: [What's the difference between STDIN and arguments passed to command?](https://unix.stackexchange.com/questions/46372/whats-the-difference-between-stdin-and-arguments-passed-to-command) and [Pass the output of previous command to next as an argument](https://unix.stackexchange.com/questions/108782/pass-the-output-of-previous-command-to-next-as-an-argument) – steeldriver Nov 02 '19 at 16:52

2 Answers2

2

You want to use command substitution.

 CLITool $(expr 1+2)

will first run the expr program with an argument of 1+2. This will output 3. Then the shell will run CLITool 3.

I would use awk to get the number, e.g.

 CLItool $(awk 'BEGIN{srand();printf("%06d\n",rand()*1000000)}')

to get a 6 digit random number with leading 0s between 0 and 1,000,000-1.

icarus
  • 17,420
  • 1
  • 37
  • 54
2

Sounds like your CLI tool simply doesn't read input from stdin. Only tools that can read input streams can be piped to. So just use command substitution instead:

CLItool $(shuf -zer -n6 {0..9})
terdon
  • 234,489
  • 66
  • 447
  • 667