Do u mean if u change the value of the cv variable then u want the value of the filename also be changed automatically. with out giving this line
file_name="$(echo "CP99978_$cv.TXT")"
Correct me If im wrong?
---------- Post updated at 02:28 AM ---------- Previous update was at 02:27 AM ----------
If ur facing a reference problem then
I think you can solve your problem by referring the following snippet
function setToXXX() {
echo changing value of $1
eval "$1='$FOO'"
}
FOO=hello
BAR=$FOO ;
echo function, FOO is $FOO
echo function, BAR is $BAR
echo "FOO IS CHANGING" ;
FOO="CHANGED VALUE" ;
setToXXX BAR # you must call this function
echo after function, BAR is $BAR
This is correct. and the filename will take the latest value.
(only of those which are assigned before defining filename variable.)
if you assign a new value to CV after filename then filename is unaffected (clear though!).
cv=1
cv=2
file=a_$cv
cv=3
$file will still contain the a_2 ( cv=2).
shell reads the commands one by one.. top to bottom.
moreover, not sure which shell you are using.. but i can see lots of syntax errors and improvement in your code as par my knowledge.
This might have been covered above.
The original statement contains too many quotes and as others have pointed out unnecessary "print" and "echo" commands. Remember that quotes act in pairs, though in this case it has no adverse effect.
Can be simplified as:
cv="CV09"
file_name="CP99978_${cv}.TXT"
Now does this actually help:
In this test code we will try four values of ${cv}.
for cv in "2007" "2008" "2009" "2010"
do
file_name="CP99978_${cv}.TXT"
echo "${file_name}"
done
---------- Post updated at 01:31 ---------- Previous update was at 00:57 ----------
My attempt to rearrange the original post follows this quote from the O/P:
Some inspired guesswork here. Could be wrong. Untested. Check before use. Any likely typos from the original such as "CV09" and "crispadm/admcrisp" (not absolute path) are carried forward verbatim.
The idea is to illustrate parameter substitution in shell with no attempt to check the Oracle commands. I have attempted to get the line continuation characters correct "\" to make some sense of the Oracle commands. I now think that there are two commands.
Guessed at sqlplus to run the second program.
Not happy that ${log} appears on both command lines, but without knowledge of the correct syntax or intentions we'll leave it to the author to decide.