- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Shell Script & variable / file name substituti...
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-04-2003 11:08 PM
12-04-2003 11:08 PM
Shell Script & variable / file name substitutions..How?
I am trying to get a script to auto email a copy of a log file. However part of the logfile name is unknown untill I do a positional grep from another file...Thats all fine but problem is when I want to cat the new file name as follows:
cat $ErrMsg | cut '-c 40-45' > $TransNum
$TransLog='/u/ai/logs/pr.tr$TransNum.log'
cat $TransLog
However script when run returns the error>
./almedi_ai.scr[32]: =/u/ai/logs/pr.tr$TransNum.log: not found.
when I echo $TransNum (which is part of the actual file name I want printed) within the script to screen it returns the correct value..?
Appreciate any help on this.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-04-2003 11:13 PM
12-04-2003 11:13 PM
Re: Shell Script & variable / file name substitutions..How?
$TransLog='/u/ai/logs/pr.tr$TransNum.log'
Variables do not get interpreted within ' marks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-04-2003 11:13 PM
12-04-2003 11:13 PM
Re: Shell Script & variable / file name substitutions..How?
In this case you should use " instead of ' to allowd variable substitution, and no $ for variable assignation :
TransLog="/u/ai/logs/pr.tr$TransNum.log"
Regards.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-04-2003 11:14 PM
12-04-2003 11:14 PM
Re: Shell Script & variable / file name substitutions..How?
export TransNum
TransLog="/u/ai/logs/pr.tr${TransNum}.log"
cat $TransLog
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-04-2003 11:14 PM
12-04-2003 11:14 PM
Re: Shell Script & variable / file name substitutions..How?
$TransLog='u/ai/logs/pr.tr'$TransNum'.log'
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-04-2003 11:14 PM
12-04-2003 11:14 PM
Re: Shell Script & variable / file name substitutions..How?
I think you need to set the $TransNum
var first.
TransNum=`cat $ErrMsg | cut '-c 40-45'`
Gideon
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-04-2003 11:19 PM
12-04-2003 11:19 PM
Re: Shell Script & variable / file name substitutions..How?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-04-2003 11:36 PM
12-04-2003 11:36 PM
Re: Shell Script & variable / file name substitutions..How?
I think you already have the solution, as pointed out by RAC, change the line
$TransLog='/u/ai/logs/pr.tr$TransNum.log'
to
TransLog="/u/ai/logs/pr.tr${TransNum}.log"
because:
a) you have to specify by curly braces where the variable begins and ends since it is not limited by a space.
b) you have to use double quotes around your variable assignment, as a dollar sign cannot be expanded inside single qoutes; try e,g, the difference between echo "$x" and echo '$x'
c) a dollar sign expands a variable, but when you assign content to a variable, you must use its name, hence
TransLog=
I hope it works; if not I am aware that my explanation looks ridiculous!
regards,
John K.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-05-2003 07:54 AM
12-05-2003 07:54 AM
Re: Shell Script & variable / file name substitutions..How?
in case the file you grep has more than one line to grep.
while read LINE
do
TransNum=`echo ${LINE} | cut -c40-45`
TransLog="/u/ai/logs/pr.tr${TransNum}.log"
cat ${TransLog}
done < ${ErrMsg}
greetings,
Michael