Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

bash or csh question..help!

Hi, I just couldnt execute 'expr' on my script.
Here's the pseudocode of what i wanted to do and I want to run it in either shells.

echo 'enter salary: '
read salary
yr = 1
while [salary -le 110000]
do
echo yr salary
salary = 'expr $salary * 1.03'
yr ='expr $yr + 1'
done

the expr in salary always fail, sometimes with non numeric arg, or if not, its salary not found. I tried to experimented all scenarios but to no success. I am confused.
Please help!!
Thanks a lot!



Comments

  • XfactorXfactor Posts: 343Member
    : Hi, I just couldnt execute 'expr' on my script.
    : Here's the pseudocode of what i wanted to do and I want to run it in either shells.
    :
    : echo 'enter salary: '
    : read salary
    : yr = 1
    : while [salary -le 110000]
    : do
    : echo yr salary
    : salary = 'expr $salary * 1.03'
    : yr ='expr $yr + 1'
    : done
    :
    : the expr in salary always fail, sometimes with non numeric arg, or if not, its salary not found. I tried to experimented all scenarios but to no success. I am confused.
    : Please help!!
    : Thanks a lot!



    In bash, not sure about csh, you can't have spaces on either side of an equal sign. So instead of
    salary = 'expr $salary * 1.03'
    use
    salary='expr $salary * 1.03'

    Same goes for
    yr='expr $yr + 1'

    X
  • marltondudemarltondude Posts: 32Member
    Hi there, it says from 'expr $salary * 1.03'.... expr non-numeric argument, is it because of 1.03???
    and also strange as it seems, the while condition gives me salary not found error... this is a pain, please help !!!!
    Thank you so much!

    : : Hi, I just couldnt execute 'expr' on my script.
    : : Here's the pseudocode of what i wanted to do and I want to run it in either shells.
    : :
    : : echo 'enter salary: '
    : : read salary
    : : yr = 1
    : : while [salary -le 110000]
    : : do
    : : echo yr salary
    : : salary =
    : : yr ='expr $yr + 1'
    : : done
    : :
    : : the expr in salary always fail, sometimes with non numeric arg, or if not, its salary not found. I tried to experimented all scenarios but to no success. I am confused.
    : : Please help!!
    : : Thanks a lot!
    :
    :
    :
    : In bash, not sure about csh, you can't have spaces on either side of an equal sign. So instead of
    : salary = 'expr $salary * 1.03'
    : use
    : salary='expr $salary * 1.03'
    :
    : Same goes for
    : yr='expr $yr + 1'
    :
    : X
    :

  • XfactorXfactor Posts: 343Member
    : Hi there, it says from 'expr $salary * 1.03'.... expr non-numeric argument, is it because of 1.03???
    : and also strange as it seems, the while condition gives me salary not found error... this is a pain, please help !!!!
    : Thank you so much!
    :
    : : : Hi, I just couldnt execute 'expr' on my script.
    : : : Here's the pseudocode of what i wanted to do and I want to run it in either shells.
    : : :
    : : : echo 'enter salary: '
    : : : read salary
    : : : yr = 1
    : : : while [salary -le 110000]
    : : : do
    : : : echo yr salary
    : : : salary =
    : : : yr ='expr $yr + 1'
    : : : done
    : : :
    : : : the expr in salary always fail, sometimes with non numeric arg, or if not, its salary not found. I tried to experimented all scenarios but to no success. I am confused.
    : : : Please help!!
    : : : Thanks a lot!

    The expr looks fine to me. Here is what I do notice.
    The while loop, you need to add a $ sign for salary to access the value in the variable. You also need a space between $salary and [ and 110000 and ]. For example:
    while [ $salary -le 110000 ]
    Again, you need to get rid of the spaces in your assignments. You have to have an assignment like this:
    yr=1
    with no spaces in the expression.
Sign In or Register to comment.