Results 1 to 5 of 5
  1. #1

    Bash: simple string argument

    I'm trying to figure it out how to work with shell string arguments.

    Code:
    ## Script Usage
    if [ ! -n "$1" ]
    then
      echo "Usage: `basename $0` <NUMBER> <MESSAGE>"
      exit $E_BADARGS
    fi
    
    
    echo $2 | gnokii --sendsms $1
    ./sendsms.sh 968169605 hello world -> bash will detect hello as second argument and world as a third instead of a single string argument.

  2. #2
    Join Date
    Feb 2003
    Location
    Canada
    Posts
    958
    You could try enclosing hello world in quotes.

    ie.
    'hello world'

  3. #3
    Quote Originally Posted by Adam-AEC View Post
    You could try enclosing hello world in quotes.

    ie.
    'hello world'
    I've tried that without sucess

  4. #4
    Join Date
    Oct 2002
    Location
    Canada
    Posts
    3,100
    cat argtest.sh
    Code:
    #!/bin/sh
    
    echo 'arg 1: '$1
    echo 'arg 2: '$2
    echo 'arg 3: '$3
    ./argtest.sh blah hello world
    arg 1: blah
    arg 2: hello
    arg 3: world
    ./argtest.sh blah hello\ world
    arg 1: blah
    arg 2: hello world
    arg 3:
    ./argtest.sh blah "hello world"
    arg 1: blah
    arg 2: hello world
    arg 3:

  5. #5
    Join Date
    May 2006
    Location
    India
    Posts
    661
    A "shift" command would put the message string into the variable $* !! Try the code below.
    Code:
    set 968169605 hello world
    echo $*
    echo $1
    shift
    echo $*
    good luck
    SparkSupport.Com - The Premier Tech Company
    Cloud Solutions|Email Infra setup|VOIP|Video Streaming|Software Development
    Email: [email protected] Phone : 1- 408-600-1449 | Skype : shijils

Posting Permissions

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