I have a shell script name count.sh; inside this script I have multiple variables, like
$INPUT_1, $INPUT_2, $OUTPUT_1, $OUTPUT_2; each variable represents a file. I want to count the lines of each file with wc -l , I tried wc -l $INPUT_1 and it worked, but what I want to do is to find a way to apply wc -l on every variable whose name contains the keyword INPUT or OUTPUT, similar principle with ls *keyword*. I am not sure if it is possible.
lsis not a keyword at all -- it's an external command; if it didn't exist in/binor/usr/binit would just be a "command not found" error.INPUT_1/INPUT_2/ etc, have you considered using an array?inputs=( [1]="something" [2]="something else" ), then it's justfor input in "${inputs[@]}"; do ...set | sed -n '/^[_[:alpha:][[:alnum:]_]*=/s/=.*//p'to get a list of all variables, exported and not exported, and you can then filter that to select the names you want (grep -E -e 'INPUT|OUTPUT') and then you have variable names — and if you getvarname=INPUT_1, you can use${!varname}to get the value of$INPUT_1. It isn't a good way of doing things, though.