Solved

Bash variable inside another varaible

Posted on 2010-09-20
2
177 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
Comment Utility
Just needs braces

ORIG_FILE=File_${MDATE}_vulndata.csv
0
 

Author Comment

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

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Background Still having to process all these year-end "csv" files received from all these sources (including Government entities), sometimes we have the need to examine the contents due to data error, etc... As a "Unix" shop, our only readily …
Recently, an awarded photographer, Selina De Maeyer (http://www.selinademaeyer.com/), completed a photo shoot of a beautiful event (http://www.sintjacobantwerpen.be/verslag-en-fotoreportage-van-de-sacramentsprocessie-door-antwerpen#thumbnails) in An…
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…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

772 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now