- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- variable substitution
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-19-2001 01:50 PM
12-19-2001 01:50 PM
The following problem I am facing is very silly.
I am trying to get the value of variable
$script from a text file.
See below
$ script=$(grep "^#/script=" tcrontab2958.txt|cut -f2 -d=)
$
$ echo $script
$OC_APPL/xibs/prs_exec.sh
$ cat $script
cat: Cannot open $OC_APPL/xibs/prs_exec.sh: No such file or directory
------------
But both the variable $OC_APPL and file prs_exec.sh are present.
---------------
$ echo $OC_APPL
/opt/ORACLE/oclin/40/dev/aot
$ ll $OC_APPL/xibs/prs_exec.sh
-rwxr-x--- 1 opapps oclin 0 Dec 5 16:25 /opt/ORACLE/oclin/40/h
The question is why the variable $script is unable to substitute the variable $OC_APPL in its value.
TIA,
Kris
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-19-2001 01:54 PM
12-19-2001 01:54 PM
Re: variable substitution
script=$(grep "^#/script=" tcrontab2958.txt|cut -f2 -d=)
to:
script=`grep "^#/script=" tcrontab2958.txt|cut -f2 -d=`
also check to see the working directory is appropriate for the file, or add the full pathname if you can.
--
mark
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-19-2001 01:58 PM
12-19-2001 01:58 PM
Re: variable substitution
I don't know if you checked this, but see if your permissions and groups are correct.
It might not be able to see the file because you don't have read access to that file because it is owned by another user and or is in another group.
I hope this helps
Maria
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-19-2001 02:01 PM
12-19-2001 02:01 PM
Re: variable substitution
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-19-2001 02:03 PM
12-19-2001 02:03 PM
Re: variable substitution
The question is why the variable $script is unable to substitute the variable $OC_APPL in its value
You need to use "eval" to get the shell to do the substitutio of $OC_APPL before it assigns it to $script.
--
mark
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-19-2001 02:11 PM
12-19-2001 02:11 PM
Re: variable substitution
It is not working that way. See below. Thanks,
$ `grep "^#/script=" tcrontab2958.txt|cut -f2 -d=`
sh: $OC_APPL/xibs/prs_exec.sh: not found.
$ eval `grep "^#/script=" tcrontab2958.txt|cut -f2 -d=`
$ eval $(grep "^#/script=" tcrontab2958.txt|cut -f2 -d=)
$ script=$(eval `grep "^#/script=" tcrontab2958.txt|cut -f2 -d=`)
$ echo $script
$ cmd=`grep "^#/script=" tcrontab2958.txt|cut -f2 -d=`
$ script=`eval $cmd`
$ echo $script
Kris
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-19-2001 02:16 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-19-2001 02:19 PM
12-19-2001 02:19 PM
Re: variable substitution
script=`grep "^#/script=" tcrontab2958.txt|cut -f2 -d=`
will extract the line from file tcrontab2958.txt that matches the grep. In reading your last response, am I correct in thinking that this line will contain the text OC_APPL? If so, then there is no way to get the shell to evaluate that, as it is just sees that as text.
If OC_APPL is a valid variable within the script that is doing the above grep, then you can put it together with the $script variable like:
script=$OC_APPL$script.
If this does not correctly address the situation, perhaps if you could post the line from the file you are grepping out, that would help.
--
mark
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-19-2001 05:51 PM
12-19-2001 05:51 PM
Re: variable substitution
"$OC_APPL/xibs/prs_exec.sh" with "${OC_APPL}/xibs/prs_exec.sh " ?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-19-2001 07:07 PM
12-19-2001 07:07 PM
Re: variable substitution
Use a combination of sed and xargs. I have tested it to work for your case. In the below testing, the variable OC_APPL contains the path of subdirectory a.
=====================================
$ echo $OC_APPL
a
$ echo $script
$OC_APPL/xibs/prs_exec.sh
$ echo $script|sed -e "s/\$OC_APPL/$(echo $OC_APPL)/g"|xargs ls
a/xibs/prs_exec.sh
$ echo $script|sed -e "s/\$OC_APPL/$(echo $OC_APPL)/g"|xargs cat
correct
=====================================
Hope this helps. Regards.
Steven Sim Kok Leong
Brainbench MVP for Unix Admin
http://www.brainbench.com
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-19-2001 07:09 PM
12-19-2001 07:09 PM
Re: variable substitution
What Darrell suggested will also work. His method is much neater than mine.
=========================================
$ echo $script
$OC_APPL/xibs/prs_exec.sh
$ cat `eval echo $script`
correct
=========================================
Hope this helps. Regards.
Steven Sim Kok Leong
Brainbench MVP for Unix Admin
http://www.brainbench.com