How to read a list of paths from a file?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to read a list of paths from a file?
# 1  
Old 10-11-2009
How to read a list of paths from a file?

Hi everyone! I'm pretty bad at shell scripting and I am trying to create a java launcher. The idea is to store in a configuration file different paths (each for a different java version) and then, run a .sh file that would read the specified java path and execute the .jar file. This is what i have so far.

Content of file: Config.cfg
Code:
[JavaPaths] 
Java6=./jre/bin/java

Content of file: JavaLauncher.sh
Code:
#!/bin/bash
MYVAR=`awk -F= '/Java6=/ { print $2 }' Config.cfg`
echo "$MYVAR"
echo "$MYVAR -jar jarFile.jar"
$MYVAR -jar jarFile.jar

The echos are there for debugging purposes. Both files are in the same directory in which i also have the jre folder.

After executing
Code:
./JavaLauncher.sh

I get this:
Code:
./jre/bin/java
 -jar jarFile.jar
: No such file or directoryre/bin/java

This is what I am not getting:
  1. Why does the 2nd line not contain the variable and the 1st one does?
  2. Why does the 3rd line states there is no such file or directory while ./jre/bin/java -jar jarFile.jar runs the jar file perfectly?
  3. Why is the 3rd line echoed that way?
Any help would be appreciated. Thanks in advance Smilie
# 2  
Old 10-11-2009
Quote:

After executing
Code:
./JavaLauncher.sh

I get this:
Code:
./jre/bin/java
 -jar jarFile.jar
: No such file or directoryre/bin/java


Why does the 3rd line states there is no such file or directory while ./jre/bin/java -jar jarFile.jar runs the jar file perfectly?
Any help would be appreciated. Thanks in advance Smilie
The error message is reporting that re/bin/java is not a directory, not ./jre/bin/java
# 3  
Old 10-11-2009
Quote:
Originally Posted by mostacholoco
Content of file: Config.cfg
Code:
[JavaPaths] 
Java6=./jre/bin/java

Use the full path in your configuration file.
# 4  
Old 10-11-2009
I think this would be tighter as it seems a little counter intuitive to set the field separator to = then include the = in the pattern match. At least this way you are explicitly testing $1 and $2 rather than the whole of $0.

Code:
MYVAR=`awk -F= '$1 ~ /Java6/ { print $2 }' Config.cfg`
echo "$MYVAR"
echo "$MYVAR -jar jarFile.jar"
$MYVAR -jar jarFile.jar

As danmero says though, your problem is the path.
# 5  
Old 10-11-2009
Hi. Yes, that's what it is being echoed, and I don't know why. The first 3 letters are being erased.
If i set the java path in the Config.cfg file to
Code:
/full/path/to/java/jre/bin/java

The output will be:
Code:
/full/path/to/java/jre/bin/java
 -jar jarFile.jarjre/bin/java
: No such file or directoryll/path/to/java/jre/bin/java

I think getting an answer to the first question would answer the rest Smilie

Quote:
I think this would be tighter as it seems a little counter intuitive to set the field separator to = then include the = in the pattern match
Yes, I agree. I just wanted to make sure it would work in case the path had a "Java6" inside of it. Anyway I also changed it and still had the same results.

Quote:
As danmero says though, your problem is the path.
I don't think it's the path. Even if it was, that wouldn't explain why the 2nd line echoed does not contain the variable and the 1st one does. Am I properly assigning the variable?
# 6  
Old 10-11-2009
Hi.

I tried what you had in your original post, and there's no problem with it. (even on Solaris - where odd-awk-goings-on are known to occur!).

What shell are you using?

Are there maybe some hidden characters in your config file, or script (use the "od" utility to have a look)?
# 7  
Old 10-11-2009
Wow. That was it! There were hidden characters on my script! Wouldn't ever think of it. Thank you all for the help! Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Read a lis, find items in a file from the list, change each item

Hello, I have some tab delimited text data, file: final_temp1 aname val NAME;r'(1,) 3.28584 r'(2,)<tab> NAME;r'(3,) 6.13003 NAME;r'(4,) 4.18037 r'(5,)<tab> You can see that the data is incomplete in some cases. There is a trailing tab after the first column for each incomplete row. I... (2 Replies)
Discussion started by: LMHmedchem
2 Replies

2. UNIX for Dummies Questions & Answers

Read workstation list from file und run command

Hi, how do I read in a file which includes a list of workstations and then run a command for each workstation ? I am unclear which command to use to read in , or is this not possible ? Thanks, (3 Replies)
Discussion started by: manni2
3 Replies

3. UNIX for Dummies Questions & Answers

Determining file size for a list of files with paths

Hello, I have a flat file with a list of files with the path to the file and I am attempting to calculate the filesize for each one; however xargs isn't playing nicely and I am sure there is probably a better way of doing this. What I envisioned is this: cat filename|xargs -i ls -l {} |awk... (4 Replies)
Discussion started by: joe8mofo
4 Replies

4. UNIX for Dummies Questions & Answers

cat a list of directory paths only to a file

Hi! I would like to funnel a series of directories and subdirectories into a text file. This is the output I would like to see from a find command: /mypath/ABC_01/VISIT_01 /mypath/ABC_01/VISIT_02 /mypath/ABC_01/VISIT_03 /mypath/ABC_02/VISIT_01 /mypath/ABC_03/VISIT_01 I've tried: find... (2 Replies)
Discussion started by: goodbenito
2 Replies

5. Shell Programming and Scripting

Read file with paths in it

Hi, I have a file as followed : 100.100.100.100 \\server\volume\path\file.pdf My script : counter=1 while read -r myline do if then FTPHOST=$myline fi if then SERVERPATH=$myline fi (4 Replies)
Discussion started by: FrankToy
4 Replies

6. Shell Programming and Scripting

Need help with awk - how to read a content of a file from every file from file list

Hi Experts. I need to list the file and the filename comes from the file ListOfFile.txt. Basicly I have a filename "ListOfFile.txt" and it contain Example of ListOfFile.txt /home/Dave/Program/Tran1.P /home/Dave/Program/Tran2.P /home/Dave/Program/Tran3.P /home/Dave/Program/Tran4.P... (7 Replies)
Discussion started by: tanit
7 Replies

7. Shell Programming and Scripting

read from a file to a list

Hello there, I have a file that contents a list of email address, and each is separated by new lines. I want to read the first email address into TO: filed and the rest into a list and goes to cc field. I plan to use mailx to send the email. I inserted the email addresses into an array, but what... (4 Replies)
Discussion started by: pinkgladiator
4 Replies

8. Shell Programming and Scripting

read list of filenames from text file and remove these files in multiple directories

I have a large list of filenames from an Excel sheet, which I then translate into a simple text file. I'd like to use this list, which contains various file extensions , to archive these files and then remove them recursively through multiple directories and subdirectories. So far, it looks like... (5 Replies)
Discussion started by: fxvisions
5 Replies

9. Shell Programming and Scripting

read list of filenames from text file, archive, and remove

I posted a week ago regarding this scripting question, but I need to revisit and have a few more questions answered.. User cfajohnson was extremely helpful with the archive script, but clarification on my part is needed to help steer the answer in a direction that works in this particular... (5 Replies)
Discussion started by: fxvisions
5 Replies

10. UNIX for Dummies Questions & Answers

List current paths of users

Looking for a command which shows the current path of other users. Similiar to the PWD command. Need to be able to see which part of the system the user is logged on to. Thanks G (4 Replies)
Discussion started by: Gandalf77
4 Replies
Login or Register to Ask a Question