- I am writing to a flat file the name of the source to be copied and the destination path as to where it is to be copied to.
Sample flat file:
Abc.scr $DESTN_PATH/test
Def.scr $DESTN_PATH/new
- I am reading the source name from this file from a shell script and replacing in the cp command. For example in the file above filename=abc.scr destn= $DESTN_PATH/test
So in shell script I am executing: cp $filename $destn
The issue I am facing here is that in the cp command the value of the environment variable $DESTN_PATH is not replaced, hence the file is copied correctly.
First off, if this:
is what you really have in your script then it will not work because of the superfluous space between "=" and "$". If it was just a copy error consider this point to be moot.
Without regard to this, if i have understood you correctly:
You have a file like this:
and you read it something like this:
and you expect the "$DEST" to be expanded by the shell? Well, this won't work, because of the evaluation process of the shell. When it evaluates "$TGT" all the variable evaluation is done and to further evaluate the resulting "$DEST/..." would require the variable substitution process to restart. I have described this in detail in this thread.
The solution is the same as in the other thread and for the same reasons: use eval.
Still, this is a unsatisfying solution, because it is inherently problematic. You might want to create a more robust solution like this:
The first non-comment line of your input file shall be of the form "DEST=/some/path". Multiple lines of this form are allowed and change the value of "$DEST" until the next occurrence of such a line. This is parsed by your script and used to set the value of DEST:
Sample of input file:
The expected output from such an input would be like this:
Here is a sketch of such a script (replace "<spc>" and "<tab>" with the respective literal characters):
cat test.ksh
#!/usr/bin/ksh
VAR="Dear Friends \n How are you? \n Have a nice day \n"
export VAR
echo "Inside test.ksh";
./test.pl
cat test.pl
#!/usr/bin/perl
print "Inside test.pl \n";
print "$VAR";
Output:
./test.ksh
Inside test.ksh
Inside test.plWhat I want to achieve is, I... (1 Reply)
Hello All,
I don't write scripts very often, and in this case I am stumped, although it may be a bug in the version of bash I have to use (it's not my system).
I want to extract a specific string snippet from a block of text (coming from a log file) that is dependent on a bunch of other... (1 Reply)
Hi,,
Let example cmd: $$config/all
Here I want to replace or subsitute blank space and also with any other character in place of "$" sign...and also want to replace backslash (/) with forward (\)......in expect script
please could any one help on this.....thank you (2 Replies)
hello everyone,
I have file with de-limited values in random order shown below, where C1V0 represents column1 value1,
C2V0 represents column2 value 2, and so on.
Column0 is a constant value which i didn't represent in the sample input format.
Column1 is a numeric column.
Column2 is a... (0 Replies)
Hello,
First post for Newbie as I am stumped. I need to get certain elements for a specific PID from the ps command. I am attempting to pass the value for the PID I want to retrieve the information for as a variable. When the following is run without using a variable, setting a specific PID,... (3 Replies)
Hi,
I am using git bash terminal window to do git operations. I have set the prompt string variable PS1 in the ~/.bashrc file as follows:
export PS1=" "
This is intended to show me the current git branch's name which is active as part of the prompt string. But, the problem is when I do a git... (2 Replies)
RedHat 5
KSH
I am creating an array, and then using case to go through and count for specific words. Then the count gets stored as an expression.
string='ftp rcp rsh telnet ftp ftp'
set -A myarray $string
FTPCOUNT="0"
for command in ${myarray}
do
case $command in
ftp) FTPCOUNT=`expr... (2 Replies)
Hi All,
I have a file which has hundred of records with fixed number of fields. In each record there is set of 8 characters which represent the duration of that activity. I want to sum up the duration present in all the records for a report. The problem is the duration changes per record so I... (5 Replies)
Hello there,
first of all, don't hesitate to notify me if I misbehave. I'm a newbe in the use of this site, and in unix too (in english as well :-)
Well, if someone hat a little time to waste, could he explain to me this strange behavior.
I'm using ksh under AIX.
cdeset=$(su - db2inst1 -c... (8 Replies)
Hi,
I am working on PGP encryption. I am getting public keys from some file.
One of the key has dollar sign in it "$" Example: "abc$123"
echo 'passphrase='$passphrase --> Giving correct value abc$123
But if I use $passphrase in PGP command getting Invalid passphrase error.
If I... (10 Replies)