Question

I would like to execute a program that launches, asks for a number, and then output my number reversed.

For example:

bob@bobby:~$ ./programm 
Number: 123456
654321 !
bob@bobby:~$`

How could i create a bash script, to execute the program with a chosen number? It's like I execute the program like that ./programm 123456 but I can't put my number in parameter, so is there a way to launch the program then autowrite my choosen number, then validate?

Was it helpful?

Solution

The first argument passed to the command will be found in the positional parameter $1. As pointed out in the comments, you can use the rev command to reverse the order of the characters in the string. Your script might look something like

#!/bin/bash

printf "%s !" "$(rev "$1")"
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top