setting directory variable?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting setting directory variable?
# 1  
Old 07-23-2009
setting directory variable?

I have the following script and would like to know how to set the variable correctly.

FTP downloads the .rpm to the current directory, so the RPM command needs to know the directory it is in.

I could use ./test-application-1.0.i386.rpm to execute the command, but is there a way to set the variable, where CWD= current directory?

Code:
#!/bin/sh

CWD='???'

wget ftp://ftp:password@10.10.1.1://test-application-1.0.i386.rpm 

rpm -i /$CWD/test-application-1.0.i386.rpm

eof

# 2  
Old 07-23-2009
I would think you could just:

Code:
rpm -i `pwd`/test-app-1.i386.rpm

or

Code:
CWD=`pwd`

# 3  
Old 07-23-2009
Or just change CWD to PWD...
# 4  
Old 07-23-2009
Code:
CWD='pwd'

I tried that, but it comes out as:

Code:
rpm -i /pwd/test-app-1/i386.rpm

it reads as text and not as a command
# 5  
Old 07-23-2009
You used single quotes, not backticks. single quote: ' backtick: `. Very subtle but not the same!

In any case backticks are not POSIX standard. You should use $(pwd). I don't know why anyone uses backticks actually, they're a nightmare to see sometimes!

In any case on top of that, changing CWD to PWD is easier!
# 6  
Old 07-23-2009
Thanks Peterro

Thanks Scottn - I didn't even know that key existed. That solved it for me.
# 7  
Old 07-23-2009
That's cool Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Setting Variable to oldest file in a directory

I am using a bash script to perform some automated maintenance on files in a directory. When I run the script using $sh -x script.sh <directory> the script works fine. It sets the variable to the oldest file, and continues on. However when I run the script like this $./script.sh <directory>, it... (5 Replies)
Discussion started by: spaceherpe61
5 Replies

2. Shell Programming and Scripting

Help with setting a variable!

I am working within a while loop and i am trying to set a variable that will read out each count of the files. the problem is the count variable i have set up gives me a total and not the individual count of each file. in the data area there is 4 abc.dat and 1 def.dat. how can i do this??? ... (2 Replies)
Discussion started by: Pablo_beezo
2 Replies

3. UNIX for Dummies Questions & Answers

setting a variable

In my script, I have the following command.... du -sk `ls -ltd sales12|awk '{print $11}'`|awk '{print $1}' it returns the value 383283 I want to modify my script to capture that value into a variable. So, I try doing the following... var1=`du -sk `ls -ltd sales12|awk '{print... (5 Replies)
Discussion started by: tumblez
5 Replies

4. Shell Programming and Scripting

Setting variable

How do you set a varible with information that contains a string and also another variable? For example: subject="Attention: $name / This $type needs your attention" The $xxxx are of course other variables that I instantiated earlier. Is it like Java where you have to use double quotes and... (1 Reply)
Discussion started by: briskbaby
1 Replies

5. Shell Programming and Scripting

Setting the right directory as non-empty

Hi guys, I've been trying to get this part of my script to work for ages and now it's getting me annoyed!! So i thought a fresh group of eyes could see where i'm going wrong! The idea is getting a directory and all its files moved to a temp folder, but similar to the rm -ir command where it... (0 Replies)
Discussion started by: olimiles
0 Replies

6. Shell Programming and Scripting

Variable setting help please

L=0 cat test.sh | while read line do L='expr $1 + 1' echo $L done echo $l >>> the echo $L at the end produces 0 but i actually want it to produce the number of lines - any idea why this is happening? (16 Replies)
Discussion started by: penfold
16 Replies

7. UNIX for Dummies Questions & Answers

Setting Directory Time

How would I modify the time of a directory? The touch command appears to only work on files and I searched through the threads looking for an example on dealing with directories. I have a directory that has a recent date, but none of the files within the directory are recent. I'd like to set... (2 Replies)
Discussion started by: jgordon
2 Replies

8. UNIX for Dummies Questions & Answers

Setting a variable

I want to set a variable to be any number of dashes. Rather than doing the following: MYVAR="------------------" I'd like to be able to set the variable to, say, 80 dashes but don't want to have to count 80 dashes. Is there a way to do this? (2 Replies)
Discussion started by: photh
2 Replies

9. Programming

setting CC variable

I am trying to install GCC-3.1.1 on an SGI Indigo2. I already have MIPSpro 7.2.1 installed. However, when I try to configure GCC-3.1.1, I get the message "cc ERROR: cc -o conftest -g failed, You must set the environment variable CC to a working compiler." What is the name of the MIPSpro c++... (1 Reply)
Discussion started by: mdbanas
1 Replies

10. UNIX for Dummies Questions & Answers

setting CC variable

I am trying to install GCC-3.1.1 on an SGI Indigo2. I already have MIPSpro 7.2.1 installed. However, when I try to configure GCC-3.1.1, I get the message "cc ERROR: cc -o conftest -g failed, You must set the environment variable CC to a working compiler." What is the name of the MIPSpro c++... (1 Reply)
Discussion started by: mdbanas
1 Replies
Login or Register to Ask a Question