Hi
I am facing a problem.
export local_folder=/opt/app/
cd /opt/app/abc/
abcversion="abc*" (abcga5 is inside /opt/app/abc/)
echo $abcversion (it echoes the correct version as abcga5 )
Now when I reuse the value of abcversion for a below path:
export ABC_HOME=/opt/app/abc/$abcversion/
echo "$ABC_HOME"
It prints
/opt/app/abc/abc*/
How can i get the actual value of abcversion in another variable assignment?
I tried searching the net and various tweaks but didnt work.
Thanks
When you assign
abcversion="abc*"
then $abcversion will contain just "abc*". It will not be set to "abcga5" because the quotes prevent globbing.
In the next line you do:
echo $abcversion
which is expanded by the shell to
echo abc* and only then the abc* is expanded to abcga5.
If you do want the variable "abcversion" have the value of abcga5 you should omit the quotes in the assignment:
abcversion=abc*
I tried removing the quotes and here are the results:
export local_folder=/opt/app/
cd /opt/app/abc/
abcversion=abc* (abcga5 is inside /opt/app/abc/)
echo $abcversion (it echoes the correct version as abcga5 )
export ABC_HOME=/opt/app/abc/$abcversion/
echo "$ABC_HOME"
/opt/app/abc/abc*/
but I need this:
/opt/app/abc/abcga5
The double quotes prevent wildcard expansion, but not in the assignment ( var=pattern*
is the same as var="pattern*"
),
but they do make a difference when used with the echo statement. To get the wildcard * to match, they should be left out:
echo $ABC_HOME
However, if there are multiple matches then you would get this:
echo $ABC_HOME
/opt/app/abc/abcga5 /opt/app/abc/abcga6 /opt/app/abc/abcga7
Hi
Its still not working. i removed quotes from everything:
See below:
cd /opt/app/abc/
abcversion=abc* (abcga5 is inside /opt/app/abc/)
echo $abcversion
echoresult:
abcga5
export ABC_HOME=/opt/app/abc/$abcversion/
echo $ABC_HOME
echoresult:
/opt/app/abc/abc*/
Remove the trailing /
Otherwise only matching directories are displayed.
Scrutinizer is right when he says: "the assignment ( var=pattern*
is the same as var="pattern*"
)". It can be tested by adding quotes around the argument of echo:
abcversion=abc*
echo "$abcversion"
abc*
To activate wildcard expansion you should use an assignment like this:
abcversion=$(ls abc*)
echo "$abcversion"
abcga5
And also MadeInGermany is right when he says to remove the trailing slash in
export ABC_HOME=/opt/app/abc/$abcversion/
(unless abcga5 is a directory).
Note: think about what the script should do when more files match the wildcard. Test it.