Solved

Bash variable inside another varaible

Posted on 2010-09-20
2
181 Views
Last Modified: 2013-12-26
Looking to find out how to place a variable inside a variable.  The situation is this.  Every month a vulnerability scan is done using nessus and then exported to csv and I have a script to parse and clean out the know exceptions from the csv file.

Here is the initial script:

#### Variables
## Original Files
ORIG_FILE=File_090110_vulndata.csv
## Cleansed Files
NEW_FILE_CLEANSED=File_090110_vulndata_cleansed.csv
## Exceptions Files
NEW_FILE_EXCEPT=File_090110_vulndata_exceptions.csv

egrep -v "^.(40802|40803|40804|40805|42119|43875|44643|4550|44060|18405)" $ORIG_FILE > $NEW_FILE_CLEANSED

egrep "^.(Id|40802|40803|40804|40805|42119|43875|44643|4550|44060|18405)" $ORIG_FILE > $NEW_FILE_EXCEPT

Open in new window


Now what I am trying to do is include a variable which would include the date and use this new variable inside the file name so that every month one would just have to change the date in one spot.  Using this example the script would look like this:

#### Variables
MDATE=090110
## Original Files
ORIG_FILE=File_$MDATE_vulndata.csv
## Cleansed Files
NEW_FILE_CLEANSED=File_$MDATE_vulndata_cleansed.csv
## Exceptions Files
NEW_FILE_EXCEPT=File_$MDATE_vulndata_exceptions.csv

egrep -v "^.(40802|40803|40804|40805|42119|43875|44643|4550|44060|18405)" $ORIG_FILE > $NEW_FILE_CLEANSED

egrep "^.(Id|40802|40803|40804|40805|42119|43875|44643|4550|44060|18405)" $ORIG_FILE > $NEW_FILE_EXCEPT

Open in new window


However, this above code does not work and is the reason I am looking for assistance.
0
Comment
Question by:melod
2 Comments
 
LVL 48

Accepted Solution

by:
Tintin earned 500 total points
ID: 33721678
Just needs braces

ORIG_FILE=File_${MDATE}_vulndata.csv
0
 

Author Comment

by:melod
ID: 33721748
LOL... thanks I tried everything but braces....  Glad you picked it up so fast.  Easy points for you. Thank you!
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

The following is a collection of cases for strange behaviour when using advanced techniques in DOS batch files. You should have some basic experience in batch "programming", as I'm assuming some knowledge and not further explain the basics. For some…
How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question