variable vlaues in other files


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting variable vlaues in other files
# 1  
Old 06-09-2004
variable vlaues in other files

lets say i have a command with arguments i.e.

alt_disk_install -C hdisk1

the argument being hdisk1

this could be differnt depending on what server your on

how could i have this be a variable that refers to this value in a file

something like

alt_disk_install -C valueinfile

so basically i create a file that contains the name of the disk i want to use, and this script refers to that file for its value
# 2  
Old 06-09-2004
Assume you have a single file name that on different boxes has values and the name of the file is /path/to/whatever:
Code:
alt_disk_install -C `cat /path/to/whatever`

# 3  
Old 06-09-2004
A lot of commands will accept their input redirected from a file, e.g.

somecommand < some_file

In your case, however, I think something like

alt_disk_install -C `cat file_name`

would be more appropriate.

Cheers
ZB


EDIT: Sorry Jim, must have been typing my post whilst you were typing yours, hence the overlap in content!
# 4  
Old 06-09-2004
ZB - no problem. Smilie

It all depends on whether alt_disk_install is willing to read stdin for the disk name, or whether it expects to get it via getopts() - command line arguments.

If it can only accept one and only one disk name for a command (I think this is true) then chances are it goes with getopts. Anyway, that's my guess.
# 5  
Old 06-09-2004
Here is another option. Assume that I have a script called somescript and it needs a config file. I would call the config file something like somescript.cfg and it would contain stuff like:

THIS="something"
THAT="something else"

The key is that the config file itself is ksh code. Then in the real script I can source it with:
. /path/to/somescript.cfg

Recall that the dot command runs a subscript in the same shell. Now those variable are defined and I can just reference them.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Stack data from multiple files into one, with variable column files

Hello Gurus, Im new to scripting. Got struck with a file merge issue in Unix. Was looking for some direction and stumbled upon this site. I saw many great posts and replies but couldnt find a solution to my issue. Greatly appreciate any help.. I have three csv files -> Apex_10_Latest.csv,... (1 Reply)
Discussion started by: wamshi
1 Replies

2. UNIX for Dummies Questions & Answers

Moving files to a folder with a variable name

hello there- first post here- maybe someone can help- Basically I am trying to copy the contents of a folder to a different folder that has a variable name. the content I want to copy would be in a folder on my desktop called: myfolder the variable folder would look something like: ... (3 Replies)
Discussion started by: infothelonghaul
3 Replies

3. Shell Programming and Scripting

Replacing variable is files in same directory

Hi all, I'm writing a script to get values from the user and replace it in another file in the same directory. /usr/bin/sediff 's/$PROJECT/'$PROJECT'/' /ananth/TEMPLATE TEMPLATE is the file I want to replace the variable PROJECT from the script I'm writing but Im not getting it done. Is... (4 Replies)
Discussion started by: Ananthdoss
4 Replies

4. Shell Programming and Scripting

function for variable files

hi all this is my function #! /bin/sh awk '/ Type/ { print "m;" $4 } /IDf/ {print $3 } /IuSac/ { print $3 } /IuSac/ { print $1 }' / IBM.txt |tr '\n' ';'| perl -pi -e 's/;m//g'|cut -d ";" -f 2-5 ' >> 2m 1) i wanna make it to save output of awk in a file named by date in order not to... (3 Replies)
Discussion started by: teefa
3 Replies

5. Shell Programming and Scripting

List files to variable

Hi, I have a variable that I use in a for loop :- files="`ls -t /usr/dw/apps/work/PROJECT_NEW/SrcFiles/$1/*.txt | head -1`" This picks up *.txt files in a directory based upon the last modified date .. This variable is called in the loop to process files which are then archived. I want... (1 Reply)
Discussion started by: jmahal
1 Replies

6. Shell Programming and Scripting

variable number of input files

Hi all, I'm an extremely newbie with unix/perl. I have a perl script that I need to run on a variable number of input files (i.e., I have to run the perl script on each file, but from run to run, I have a different list of files that need to be put through this script). I think this can... (2 Replies)
Discussion started by: sunmatrix
2 Replies

7. Shell Programming and Scripting

loop through two files based on a variable

Hi guyz. i have two files. based on keys(chr1, chr2..) it has to loop through the second file of the same keys and has to take the minimum number after substraction. Sorry if I made my question complicated. file1 chr2 1989 chr2 2500 chr1 1500 file 2 chr1 1339 chr2 2000 chr2 3000... (20 Replies)
Discussion started by: nogu0001
20 Replies

8. Shell Programming and Scripting

How to search the files with the value in a variable

Hi Am taking a value in a variable and i have to use that in listing files using grep like ls -ltr | grep "$variablename" filename... but the variable contains spaces in it and i am not able to get the correct value(i.e., wid spaces) if the variable has "day 2"(wid 2 spaces) in it am... (13 Replies)
Discussion started by: sparks
13 Replies

9. Shell Programming and Scripting

How to assign files to variable

Hi All, I have many files in a directory. I want to assign these files to variable. For example: In home directory I have files called a.dat, b.dat, c.dat, e.dat and so on.... I want to assign all these files to varibale. How can I do that? Thanks (2 Replies)
Discussion started by: Bhanu72
2 Replies

10. UNIX for Dummies Questions & Answers

appending variable number of files

In a particular path of a server I have number of files.The files are generated every date with a date_mth stap on this.There are different files for different clients. For example in /data1 path i have X_0416_Score Y_0416_Score Z_0417_Score X_0417_Score A_0417_Score If i will run the... (1 Reply)
Discussion started by: dr46014
1 Replies
Login or Register to Ask a Question