Urgent!! Bash - problem using CD with variable


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Urgent!! Bash - problem using CD with variable
# 1  
Old 01-17-2007
Urgent!! Bash - problem using CD with variable

I am extracting directory path from file which is stored in a variable.

while read inputline
do
script_name=`echo $inputline | cut -d' ' -f2`
cd $script_name
done < path_scripts.txt

where as path_scripts contains

input_process.bash ~/jobs/process/input/bin

The script output says no directory present
script1.sh: cd: ~/jobs/process/input/bin: No such file or directory

This is valid directory path but still i get the error. Could you please let me know why? how to fix this?
# 2  
Old 01-17-2007
Try this:
Code:
while read field_one field_two
do
ls -ld $field_two
script_name=$field_two
cd $script_name                    ## this is silly. just use $field_two to cd
done < path_scripts.txt

If the ls -ld command returns "No such file or directory" (or some such), then that directory is not present.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Problem with awk instructions and bash variable

Hi everyone, I'm trying to write a small script to automatize row data treatment. However, I got some trouble with the awk command. I want to use awk to extract a define paragraph from a text file. The first and final lines are defined externally in two variables called debut and fin. I... (2 Replies)
Discussion started by: TeaTimeSF
2 Replies

2. Shell Programming and Scripting

Bash script - ENV Variable context problem using su

Hello I have found some piece of code to verify and then run shell script with root permission from normal user. see : http://blog.mecworks.com/articles/2006/02/23/bash-scripting-tip-running-a-script-as-root I have wrote two scripts using this tips. - one to copy file from server to local... (6 Replies)
Discussion started by: jcdole
6 Replies

3. Shell Programming and Scripting

Bash, Dynamic Variable Problem >.<

Hello, I have a problem with a bash script, I've been doing recherches but i can't make it work. It is my first time with a dynamic variable and i don't understand how to write it. #!/bin/bash USER=BARSPIN HOTKEYS_PATH="/home/$USER/Documents/bash/tibia/HOTKEYS" CFG1="A" CFG2="B"... (5 Replies)
Discussion started by: barspin
5 Replies

4. Shell Programming and Scripting

Program Bash VERY URGENT

Hello I have to do a program in Bash, need help because it does not go out for me and go enough time with this!! Five directories(boards of directors) that more occupy, arranged according to size. To measure the size of every directory(board of directors) there must not be included the size... (1 Reply)
Discussion started by: danihj
1 Replies

5. Shell Programming and Scripting

bash and ksh: variable lost in loop in bash?

Hi, I use AIX (ksh) and Linux (bash) servers. I'm trying to do scripts to will run in both ksh and bash, and most of the time it works. But this time I don't get it in bash (I'm more familar in ksh). The goal of my script if to read a "config file" (like "ini" file), and make various report.... (2 Replies)
Discussion started by: estienne
2 Replies

6. UNIX for Dummies Questions & Answers

New Variable with Existing variable( Urgent)

hi all, i want use the variable value as a new variable name. print output of new variable. for i in COMPUTER1 COMPUTER2 do flag_name=${i}_FLAG eval ${flag_name}=123 echo $i'_FLAG' done output is COMPUTER1_FLAG COMPUTER2_FLAG i need output as 123 123 (2 Replies)
Discussion started by: arvindng
2 Replies

7. UNIX for Advanced & Expert Users

Urgent-reading a variable value

Hi, I have a text file in which , I have contents like t1=abc t2=xyz t3=awe ...... I am able to read contents of these variables in a script by . /temp.txt echo $t1 Now, what my requirement is something like this a="t" i=1 echo $a$i --->this is displaying t1 (3 Replies)
Discussion started by: kaaakrishna
3 Replies

8. Shell Programming and Scripting

passing variable from bash to perl from bash script

Hi All, I need to pass a variable to perl script from bash script, where in perl i am using if condition. Here is the cmd what i am using in perl FROM_DATE="06/05/2008" TO_DATE="07/05/2008" "perl -ne ' print if ( $_ >="$FROM_DATE" && $_ <= "$TO_DATE" ) ' filename" filename has... (10 Replies)
Discussion started by: arsidh
10 Replies

9. Shell Programming and Scripting

how to store the first content of the folder in a variable?(Urgent)

Hi All, I need urgent help. Because just now i have to give this code to my client. I have a folder name is Testing. this Testing folder contains the following 3 files. 1.txt 2.txt 2.txt Now I want to store the first value of my folder in a variable say suppose $a. Means i want that... (3 Replies)
Discussion started by: sunitachoudhury
3 Replies

10. Shell Programming and Scripting

Convert bash to sh URGENT :(

Hi, I have to write a program to compare 2 files for copying. the program is ran on Solaris 5.8 like this: script.sh file1.txt file2.txt I wrote the program using bash and it took me forever since I am a beginner but it works very well. I'm getting so close to the deadline and I... (2 Replies)
Discussion started by: Chris Jones
2 Replies
Login or Register to Ask a Question