Strange shell script problem!

Posted on 2007-10-04
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?
Question by:mfarid2
    LVL 84

    Accepted Solution

          History substitutions begin with the character `!'.   They
           may  begin  anywhere  in the input stream, but they do not
           nest.  The `!' may be preceded by a  `\'  to  prevent  its
           special   meaning;  
    LVL 84

    Expert Comment

    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-
    LVL 84

    Expert Comment

    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.
    LVL 48

    Expert Comment

    What ozo said.

    I'm guessing your login shell is bash.
    LVL 51

    Expert Comment

    all shells (except plain old sh) have to escape ! with \ as it is a history meta character, even enclosed in single or double quotes
    LVL 29

    Expert Comment


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


    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
    Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
    Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
    This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.

    729 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    21 Experts available now in Live!

    Get 1:1 Help Now