Multiple variable substitution in a file in one go


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Multiple variable substitution in a file in one go
# 1  
Old 07-24-2014
Linux Multiple variable substitution in a file in one go

I have a huge script which is defining variables with full path of commands in the beginning of code and using those variables in the script.

For Example:

Code:
ECHO=/bin/echo
LS=/bin/ls
SED=/bin/sed
AWK=/bin/awk
UNAME=/bin/uname
PS=/bin/ps
DATE=/bin/date
GREP=/bin/grep


$ECHO "hello world"
$LS -ltr|$AWK '{print $NF}'
$SED 's/$.//g'
$UNAME -r
$UNAME -m
$HOSTNAME
$PS -ef|$GREP ora|$GREP -v grep
$DATE +%Y%M%D

Now i want replace all these variable with absolute path of the commands in one go.

Can you guys please help me with this.

Regards,
Veer
# 2  
Old 07-24-2014
Is this a homework assignment?

You haven't specified nearly enough to know what should be done here. And, some requirements could make this an extremely complex job requiring a full syntactic and semantic understanding of the shell you're using and of all of the commands invoked by your script.
  1. What delimits the start and end of the variable assignments to be removed and expanded by your script?
  2. Are occurrences of expansions of these variables to be replaced inside pairs of single quotes?
  3. Does your script need to be smart enough not to replace $ECHO in the command: $LS $ECHO_OLD?
  4. Does your script need to be smart enough to replace ${ECHO} as well as $ECHO?
  5. Is your script to search out and replace these variables in dotted and sourced files?
  6. What if a script creates an intermediate encoding that result in one of these variables being expanded as a side effect of running eval?
  7. What if a printf invocation leads to a string being put into a variable that will be expanded and run later in the script?

What have you tried? With what you have tried, what isn't working?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

cat file with variable substitution

MyFile contains: ALTER TABLE $DBN.$TBN ADD $COL $TYP COMPRESS ($VAL); I need to cat the file and have it substitute all of the variables with their contents. cat MyFile does not work. The following works for the first line, but errors on the second line because of the paren: $ while read... (2 Replies)
Discussion started by: Phil27577
2 Replies

2. Shell Programming and Scripting

Variable substitution

Hi, I have to write a shell script in which I have to substitute a variable within a variable. For example, var1=aaa var2=file.$var1.txt The output should be, echo $var2 file.aaa.txt Can someone please help me in getting this. I tried using eval, but it didnt work. I might be using it... (2 Replies)
Discussion started by: grajp002
2 Replies

3. Shell Programming and Scripting

How to use variable with command substitution in variable

For example I have variable like below echo $OUTPUT /some/path/`uname -n` when I try to use the variable OUTPUT like below cd $OUTPUT or cd ${OUTPUT} I am getting bad substituion error message $ cd $OUTPUT ksh: cd: bad substitution $ cd ${OUTPUT} ksh: cd: bad substitution ... (1 Reply)
Discussion started by: rajukv
1 Replies

4. Shell Programming and Scripting

Multiple variable substitution in one line

Hi, I want to get content of a$i variables with one command: a1=/tmp1.log a2=/tmp2.log for i in 1 2;do log=<some code> echo $log done and get the content of a1 and a2: /tmp1.log /tmp2.log Thanks (2 Replies)
Discussion started by: gdan2000
2 Replies

5. Programming

Makefile: multiple target variable substitution

Greetings! Basically, I would like to properly handle this with gnu make: alltools: my_tool mysecond_tool mythird_tool etc_tool %_tool: dir1/%_tool.vf dir2/%_tool/subdir2/%_tool.ver <tab>@echo done %.vf: <tab>RUN_VF $* %.ver: <tab>RUN_VER $* So, if I were to do something like:... (0 Replies)
Discussion started by: Harlinator
0 Replies

6. Shell Programming and Scripting

variable substitution

file1.ksh #!/bin/ksh test5_create="I am a man" # test5 will be dynamic and the value will be passed from command line a=${1}_create echo $a # i need the output as "I am a man" ./file1.ksh test5 # i run the script like this any suggessions guys... (1 Reply)
Discussion started by: giri_luck
1 Replies

7. Shell Programming and Scripting

Sed variable substitution when variable constructed of a directory path

Hello, i have another sed question.. I'm trying to do variable substition with sed and i'm running into a problem. my var1 is a string constructed like this: filename1 filerev1 filepath1 my var2 is another string constructed like this: filename2 filerev2 filepath2 when i do... (2 Replies)
Discussion started by: alrinno
2 Replies

8. Shell Programming and Scripting

Multiple Substitution

Hello Guys, I have some variables declared as below VARIABLE1=Table VARIABLE2=VARIABLE1 Now when I do an echo $VARIABLE2 it gives me below atrcus303{root} #: echo $VARIABLE2 VARIABLE1 I want to echo the value of VARIABLE1 using the VARIABLE2. So I tried to the below atrcus303{root} #:... (1 Reply)
Discussion started by: Mohammed
1 Replies

9. UNIX for Dummies Questions & Answers

variable substitution

Hi everyone, I have a simple question to ask : In a script that I'm writting, I need to create variables on-the-fly. For instance, for every iterartion of the following loop a var_X variable should be generated : #!/bin/ksh a="1 2 3" for i in $a do var_${i}=$i echo "${var_$i}" done ... (1 Reply)
Discussion started by: ck-18
1 Replies

10. UNIX for Advanced & Expert Users

Substitution in a variable

Hey All, I'm trying to clean up a variable using sed but It dosn't seem to work. I'm trying to find all the spaces and replace them with "\ " (a slash and a space). For Example "Hello World" should become "Hello\ World". But it does nothing. If I put it directly into the command line it works... (3 Replies)
Discussion started by: spragueg
3 Replies
Login or Register to Ask a Question