The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
assingn a variable a filename and then reading it in magnia UNIX for Dummies Questions & Answers 3 07-23-2009 01:49 PM
variable used as filename jzacsh Shell Programming and Scripting 4 05-14-2009 05:03 PM
Variable value not being fetched in the filename.. RRVARMA Shell Programming and Scripting 3 06-01-2008 06:43 AM
mv Filename variable to another filename gzs553 Shell Programming and Scripting 3 04-14-2008 05:19 PM
AWK Filename as variable firkus UNIX for Dummies Questions & Answers 4 04-16-2004 11:50 AM

Reply
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 08-24-2009
TheSMan5 TheSMan5 is offline
Registered User
  
 

Join Date: Aug 2009
Posts: 4
Inserting variable value into filename

Greetings, people of UNIX/Linux forums.

I am having a problem with a script, where I am trying to create a new variable. The value of this variable would be dependent on the value in a couple other previous variables (all variables are 2-digit integers). Here is my code:


#set the stations
set stn = `cat wind_obs_${date}.dat | cut -c 3-7`
set mth = `cat wind_obs_${date}.dat | cut -c 10-11`
set day = `cat wind_obs_${date}.dat | cut -c 13-14`
set hr = `cat wind_obs_${date}.dat | cut -c 18-19`
set lat = `cat wind_obs_${date}.dat | cut -c 34-38`
set lon = `cat wind_obs_${date}.dat | cut -c 25-30`
set nlines = `cat -b wind_obs_${date}.dat | tail -1 | cut -c 4-7`
# all variables above are being set fine

if (whichruc == 1) then
setenv RUCDATA /ldm_data/gempak/rtma/ruc_oper
set infile = ruc5_oper.2008${mth}${day}${hr}.gem #problem line
else
setenv RUCDATA /ldm_data/gempak/rtma/ruc
set infile = ruc5_back.2008${mth}${day}${hr}.gem #problem line
endif

When I run this, I get an error saying:
set: Variable name must begin with a letter.

My variable name does begin with a letter and I cannot find a way for this to work. What should I do to ensure the value of the variables go into the file name?

Thank you!
  #2 (permalink)  
Old 08-24-2009
avronius avronius is offline VIP Member  
VIP Member
  
 

Join Date: Apr 2008
Location: Calgary
Posts: 305
Simplify it - test the lines below and see how the script behaves


Code:
infile="ruc5_oper.2008$mth$day$hr.gem"
infile="ruc5_back.2008$mth$day$hr.gem"

  #3 (permalink)  
Old 08-24-2009
TheSMan5 TheSMan5 is offline
Registered User
  
 

Join Date: Aug 2009
Posts: 4
Didn't work. Same error.

I have investigated further and now think that the mth, day and hr variables are actually arrays, as they were formed by cutting/counting characters from a multi-line dat file.

Any other ideas appreciated!
  #4 (permalink)  
Old 08-24-2009
ryandegreat25 ryandegreat25 is offline
Registered User
  
 

Join Date: Jul 2009
Posts: 236
you need to "grep" the specific line here "wind_obs_${date}.dat". so the variable assignment would not be a multiline one
Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 06:16 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0