We help IT Professionals succeed at work.

Strange shell script problem!

Last Modified: 2013-12-26
I am executing a shell script as follows:

ksh /Fld1/Fld2/MyScript.ksh  /Fld1/Fld2/  WinBox UID PWD!123 /FTPFld1/FTPFLD2 FileToUpload1.txt FileToUpload2.txt

After I execute, I get the following back displayed by the system:
ksh /Fld1/Fld2/MyScript.ksh  /Fld1/Fld2/  WinBox UID PWDvi MyScript.ksh /FTPFld1/FTPFLD2 FileToUpload1.txt FileToUpload2.txt

As a result, the log in fails and I cannot upload the file. As you can see, the "PWD!987" gets replaced with "PWDvi" and the script name reappears as a parameter. Sometimes a different script name reappears as a parameter. This is very strange behavior. Can anybody shed some light?
Watch Question

Most Valuable Expert 2014
Top Expert 2015
Unlock this solution and get a sample of our free trial.
(No credit card required)
Most Valuable Expert 2014
Top Expert 2015

If you are using tcsh
   History substitution
       Each  command,  or  ``event'',  input from the terminal is
       saved in the history list.  The previous command is always
       saved, and the history shell variable can be set to a num-
       ber to save that many commands.  The histdup  shell  vari-
       able  can  be set to not save duplicate events or consecu-
       tive duplicate events.

       Saved  commands  are  numbered  sequentially  from  1  and
       stamped with the time.  It is not usually necessary to use
       event numbers, but the current event number  can  be  made
       part  of  the prompt by placing an `!' in the prompt shell

       The shell actually saves history in expanded  and  literal
       (unexpanded) forms.  If the histlit shell variable is set,
       commands that display and store history  use  the  literal

       The  history  builtin  command can print, store in a file,
       restore and clear the history list at any  time,  and  the
       savehist and histfile shell variables can be can be set to
       store the history list automatically on logout and restore
       it on login.

       History  substitutions  introduce  words  from the history
       list into the input stream, making it easy to repeat  com-
       mands,  repeat arguments of a previous command in the cur-
       rent command, or fix spelling  mistakes  in  the  previous
       command  with  little  typing  and a high degree of confi-
Most Valuable Expert 2014
Top Expert 2015

in bash
       History  expansion  is  performed immediately after a com-
       plete line is read, before the shell breaks it into words.
       It  takes  place  in two parts.  The first is to determine
       which line from the history list to use  during  substitu-
       tion.   The  second is to select portions of that line for
       inclusion into the current one.  The  line  selected  from
       the  history  is  the event, and the portions of that line
       that are acted upon  are  words.   Various  modifiers  are
       available  to  manipulate the selected words.  The line is
       broken into words in the  same  fashion  as  when  reading
       input,  so that several metacharacter-separated words sur-
       rounded by quotes are considered one word.  History expan-
       sions  are  introduced  by  the  appearance of the history
       expansion character, which is ! by  default.   Only  back-
       slash  (\)  and single quotes can quote the history expan-
       sion character.
Top Expert 2007

What ozo said.

I'm guessing your login shell is bash.
all shells (except plain old sh) have to escape ! with \ as it is a history meta character, even enclosed in single or double quotes

If the UID and PW are for  an FTP file transfer, look into setting them in the '.netrc' file to keep them secret.


Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.