Find the answer to your Linux question:
Results 1 to 3 of 3
I have a shell script which accepts 4 arguments to execute the script my.sh a b c d In the script I set F1=$1 F2=$2 F3-$3 F4=$4 When it works, ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    May 2007
    Posts
    18

    How to remove extra space in argument to shell script


    I have a shell script which accepts 4 arguments

    to execute the script
    my.sh a b c d

    In the script I set
    F1=$1
    F2=$2
    F3-$3
    F4=$4

    When it works, I'll have F1=a, F2=b, F3=c and F4=d
    I did not create the caller program. But when they make the call with an extra space between the arguments, it kills my script

    for example, when they issue
    my.sh a b c d (an extra space between a and b

    I think my script will get F1=a F2= F3=b F4=c and it will fail because the F values are wrong.

    What is the best way to check and fix the problem (i.e to protect myself from being killed). I can't do nothing about the caller mistakes.

  2. #2
    Linux Engineer
    Join Date
    Apr 2012
    Location
    Virginia, USA
    Posts
    883
    You could parse $@ manually.

  3. #3
    Linux Engineer docbop's Avatar
    Join Date
    Nov 2009
    Location
    Woodshed, CA
    Posts
    905

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •