This command will return the position (where zero is the first position) of TARGET in STRING. If the TARGET is not found a negative 1 will be returned.
NOTE: we'll use the option -nl
to append a new line to the output
and make it easier to read.
string -nl position "friend" "The people were friendly"
Would return 16
string position "tomato" "The people were friendly"
Would return -1
NOTE: To read content from standard input we use the -i -
option.
echo "The people were friendly" | string -nl -i - position "friend"
Would return 16
echo "The people were friendly" | string -nl -i - position "apple"
Would return -1