?
Solved

Strange shell script problem!

Posted on 2007-10-04
6
Medium Priority
?
235 Views
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?
0
Comment
Question by:mfarid2
6 Comments
 
LVL 85

Accepted Solution

by:
ozo earned 500 total points
ID: 20018174
      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;  
0
 
LVL 85

Expert Comment

by:ozo
ID: 20018205
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
       variable.

       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
       form.

       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-
       dence.
0
 
LVL 85

Expert Comment

by:ozo
ID: 20018240
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.
0
Transaction-level recovery for Oracle database

Veeam Explore for Oracle delivers low RTOs and RPOs with agentless transaction log backup and transaction-level recovery of Oracle databases. You can restore the database to a precise point in time, even to a specific transaction.

 
LVL 48

Expert Comment

by:Tintin
ID: 20018397
What ozo said.

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

Expert Comment

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

Expert Comment

by:MikeOM_DBA
ID: 20021640

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

http://linux.die.net/man/5/netrc
http://www.scit.wlv.ac.uk/cgi-bin/mansec?4+netrc

0

Featured Post

Get quick recovery of individual SharePoint items

Free tool – Veeam Explorer for Microsoft SharePoint, enables fast, easy restores of SharePoint sites, documents, libraries and lists — all with no agents to manage and no additional licenses to buy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
In this post we will learn different types of Android Layout and some basics of an Android App.
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.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Suggested Courses

807 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