From this question: Will ls always list the files that rm will remove? @fkraiem commented and said:
I am somewhat surprised that rm does not have a –dry-run flag…
This reminded me of a scenario I had sometime back using the seq
command to generate a sequence of numbers from 1 – 100. The problem was that the list had a prefix Item
seq 100
Generated:
1
2
3
...
100
Whereas I wanted:
Item 1
Item 2
Item 3
...
Item 100
Using the seq command as an example, is there anyway I can add a --prefix=[PREFIX]
flag that automatically adds a prefix to the generated sequence list?
I am not talking about bash aliases
Best Answer
In general, short of modifying the command's code (and recompiling, in the case of a compiled executable) you would need to write a wrapper function - either as a shell function or an executable script located ahead of the original executable in your
PATH
. It would need to:However your
seq
should already have an option to specify the number format, which may be (ab)used to get the kind of list you wantEx.
More generally, you could use
printf
e.g.printf 'Item %d\n' $(seq 1 100)
or (using bash's built-in brace expansion)printf 'Item %d\n' {1..100}
BTW
rm
does have a sort of dry-run flag,-i
or (less portably)