0

I have the following variable PARM1= APP and the value assigned to it is given in the following PARM, PARM2 = RL. If the user makes a mistake and sends a value of PARM2=-RL, the program fails. How can I do so that once I receive the values ​​if it is wrong I can correct it, that is, if I receive PARM2= -RL in my code PARM2= RL is used

I tried the following code but sed seems to be misconfigured

if [ "$PARM3" = -RL ]; 
then
   sed -i -e 's/-RL/RL/g' 
elif [ "$PARM3" = -RS ];
then
   sed -i -e 's/-RS/RS/g' 
fi
KLM
  • 27
  • 1
  • 7
  • FYI, http://shellcheck.net/ can catch this kind of problem (and others) for you automatically. – Charles Duffy Jan 24 '22 at 17:24
  • I already corrected the syntax but it seems that the sed command is not doing what it should – KLM Jan 24 '22 at 17:44
  • Re: "what it should", `sed -i` makes no sense unless you pass a filename as an argument. What do you think it "should" do? – Charles Duffy Jan 24 '22 at 17:55
  • (also, which operating system are you on? `-i` is a nonstandard extension, and the BSD and GNU variants implement it in mutually-incompatible ways). – Charles Duffy Jan 24 '22 at 17:56
  • Anyhow -- don't assume we know from looking at your code what it's "supposed" to do. If it was correct code, you wouldn't have a problem that was leading you to ask a question here in the first place. – Charles Duffy Jan 24 '22 at 17:57
  • 1
    If what you want to edit is the variable `PARM3` to remove the leading dash when it has the exact value `-RL` or `-RS` and in no other cases, doing that correctly would look like `case $PARM3 in -RL|-RS) PARM3=${PARM3#-};; esac` -- no reason to use `sed` at all. – Charles Duffy Jan 24 '22 at 17:58

0 Answers0