Solved

Bash variable inside another varaible

Posted on 2010-09-20
2
182 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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
Utilizing an array to gracefully append to a list of EmailAddresses
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…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

856 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