Use the output of a command as input to the same command in a loop
2
votes
4
answers
1585
views
So I'm trying to find a template for bash/shell script that essentially run a command, let's call it "command1" using an input "X" and then use the output of command1 on itself...but in a loop.
Here a real world example:
echo "hello" | cut -c2-
which will remove the first character at the beginning of the input string and output:
ello
Now, the above is just an example to illustrate the template mentioned above. Following this example, how could i use *command1* output:
echo "hello" | cut -c2-
But as input, in a loop, either indefinite loop or until only one byte/character remain.
So that i don't need to copy/paste the output and replace it with the old input:
echo "ello" | cut -c2-
Or need to use multiple pipe which would be too slow/inefficient.
**Simpler Explanation**
Using manual action, this would be the replacement of me(the user) copy pasting the output of the command i gave as example (or the pseudo code i described earlier) and use that as input for that same command, repeating that same action until "one" byte or char remain.
Asked by Nordine Lotfi
(2472 rep)
Jan 13, 2021, 05:50 PM
Last activity: Jan 14, 2021, 01:23 PM
Last activity: Jan 14, 2021, 01:23 PM