I would like to modify input parameters of an SH script (it begins with #!/bin/sh). I found some solutions but they don't work here and need bash. They give me bad substitution error. so I look for a solution that works in SH (or whatever it is called)
The bash_params could be like "_learn _vil=bar _meet=foo". Here "_learn" acts as a flag. I want to set some variabels based on this flag and then remove it so that I can set other variables with eval.
Also, if you know better approaches please let me know
case $bash_params in
*"_learn"*) # learn is enabled
_learn_sp=True
tt="_learn"
bash_params="${bash_params%"$tt"}" # it doesn't work
bash_params="${bash_params/_learn//}" # this gives Bad substitution error
_lsp=False
;;
eval ${bash_params}
bashbecause it gives me some other errors.evalhere is a bad idea: bash gives you tools likeprintf %qand${var@Q}that can be used to generate eval-safe strings with untrusted data, whereasshdoesn't have the tools necessary to makeevalsafe unless the strings you're passing it contain only text that your script contains strict control over (no filenames, no user-provided arguments, etc).evalis appropriate,eval "$params"is safer thaneval $params; the latter subjects you to word-splitting, globbing, and then pasting of the results back into a single string before the parsing process starts, so it's an easy way for an unexpected glob character in your arguments to cause filenames (and any code they may contain) to be injected into the code that's then run through the parser.%only removes suffixes, not arbitrary substrings.