Results 1 to 4 of 4

Thread: parameter expansion & substitution errors

Hybrid View

  1. #1
    Join Date
    Apr 2008
    Location
    Southern California, USA
    Beans
    Hidden!
    Distro
    Ubuntu Development Release

    parameter expansion & substitution errors

    I have this error that uses parameter expansion and parameter substitution, but I get errors. Can you spot the reason for the error?

    Code:
    #!/bin/sh
    
    echo "AQ wE rTy  Ui  Op"
    
    selection="AQ wE rTy  Ui  Op"
    
    choice=${selection// } #remove spaces
    
    choice2=${selection,,} #lower case
    
    echo $choice
    
    echo $choice2
    Here's the error: ./x: 5: ./x: Bad substitution

    This is just a simple snippet showing the error from a much larger script.

    I found the simple error, I just wasn't expecting it.

    The original script was showing most of the functions of zenity, found here.
    Last edited by VMC; June 15th, 2013 at 10:31 PM. Reason: error

  2. #2
    Join Date
    Apr 2012
    Beans
    7,256

    Re: parameter expansion & substitution errors

    well the obvious thing would seem to be that those are bash substitutions, and on most (Ubuntu) systems, sh is not bash

  3. #3
    Join Date
    Apr 2008
    Location
    Southern California, USA
    Beans
    Hidden!
    Distro
    Ubuntu Development Release

    Re: parameter expansion & substitution errors

    Quote Originally Posted by steeldriver View Post
    well the obvious thing would seem to be that those are bash substitutions, and on most (Ubuntu) systems, sh is not bash
    On the sh(dash) man page, was my clue. Then it hit me. First time I needed to change from sh to bash. In the past it was on another system. And in looking at code from usr/bin I found my answer. No parameter usage on using /bin/sh.

    What threw me off was the length of code from the fist 'sh' assignment in the original zenity.sh script, and the parameters in question. I'll have to check my other OS's and see if their is perhaps a link from 'sh' to 'bash' or an updated 'sh'. I'm unsure of the difference of dash 'sh' and any others.
    Last edited by VMC; June 16th, 2013 at 01:36 AM.

  4. #4
    Join Date
    Jul 2007
    Location
    Poland
    Beans
    4,499
    Distro
    Ubuntu 14.04 Trusty Tahr

    Re: parameter expansion & substitution errors

    sh is used mostly for system stuff that is supposed to be light on resources and distros apparently symlink all kinds of stardards compatible shells there, according to their needs and vision. When you write a userspace, script declare it as a bash one right off the bat with proper hashbang line to remove any ambiguosity and enjoy convenient features bash has to offer.
    if your question is answered, mark the thread as [SOLVED]. Thx.
    To post code or command output, use [code] tags.
    Check your bash script here // BashFAQ // BashPitfalls

Bookmarks

Posting Permissions

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