Find the answer to your Linux question:
Results 1 to 4 of 4
Hi, I'm having a total memory blank to why this is happening. I get the error "line 7: [: $save: integer expression expected" It's a simple script and I'm having ...
  1. #1
    Just Joined!
    Join Date
    Dec 2006
    Posts
    12

    Simple problem - Bash script

    Hi,

    I'm having a total memory blank to why this is happening. I get the error

    "line 7: [: $save: integer expression expected"

    It's a simple script and I'm having a total memory blank. Any ideas?

    #!/bin/bash

    zenity --info --text="This will now display all open files."
    gksudo lsof | zenity --text-info --width 530
    save=$(zenity --question --text="Would you like to save this list?")

    if [ '$save' -eq '0' ]
    then
    szSavePath=$(zenity --file-selection --save --confirm-overwrite)
    gksudo lsof > $szSavePath
    fi

    ./main.sh

    exit 0

    Thanks, Shaun.

  2. #2
    Linux Newbie
    Join Date
    Jan 2008
    Location
    Canada
    Posts
    109
    Quote Originally Posted by Shauntp View Post
    Hi,

    I'm having a total memory blank to why this is happening. I get the error

    "line 7: [: $save: integer expression expected"

    It's a simple script and I'm having a total memory blank. Any ideas?

    #!/bin/bash

    zenity --info --text="This will now display all open files."
    gksudo lsof | zenity --text-info --width 530
    save=$(zenity --question --text="Would you like to save this list?")

    if [ '$save' -eq '0' ]
    then
    szSavePath=$(zenity --file-selection --save --confirm-overwrite)
    gksudo lsof > $szSavePath
    fi

    ./main.sh

    exit 0

    Thanks, Shaun.
    Hi Shauntp
    For whatever reason the return value for the variable 'save' is not an integer.
    save=$(zenity --question --text="Would you like to save this list?") <--- make sure that the value returned by the assignment you made, is an Integer Value and not a Ascii 0 place holder. This means that although the value may be zero it is not an integer variable but rather a character variable. Hope this helps. Cheers...
    Robert

  3. #3
    Just Joined! cfajohnson's Avatar
    Join Date
    May 2007
    Location
    Toronto, Canada
    Posts
    52
    Quote Originally Posted by Shauntp View Post
    Hi,

    I'm having a total memory blank to why this is happening. I get the error

    "line 7: [: $save: integer expression expected"

    It's a simple script and I'm having a total memory blank. Any ideas?

    #!/bin/bash

    zenity --info --text="This will now display all open files."
    gksudo lsof | zenity --text-info --width 530
    save=$(zenity --question --text="Would you like to save this list?")

    if [ '$save' -eq '0' ]
    then
    szSavePath=$(zenity --file-selection --save --confirm-overwrite)
    gksudo lsof > $szSavePath
    fi

    ./main.sh

    exit 0

    Thanks, Shaun.

    You are comparing a literal $save with 0. Variables are not expanded inside single quotes.

    Code:
    if [ "$save" -eq 0 ]
    A second problem is that $save contains the output of zenity -- and there is none. The return code contains the value you want.

    Code:
    zenity --question --text="Would you like to save this list?"
    if [ $? -eq 0 ]

  4. #4
    Just Joined!
    Join Date
    Dec 2006
    Posts
    12
    Thankyou! It worked.

Posting Permissions

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