Error in reading variable in shell script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Error in reading variable in shell script
# 1  
Old 10-10-2014
Error in reading variable in shell script

Hello all,
I have small script:
# SCRIPT
Code:
COMMONFILEPATH=$WORKDIR/samples/
FILEPATH=$COMMONFILEPATH/syncEx_tautau_Christian_Oct2014/output_crab/
FILENAME=$FILEPATH/TTFH_MC_SUSYGluGluToHToTauTau_M-130_8TeV-pythia6-tauola

./main $FILENAME"*root" $LUMIFILE  $CONFIGDEFAULTFILE

Where the FILENAME actually refer to :
Code:
TTFH_MC_SUSYGluGluToHToTauTau_M-130_8TeV-pythia6-tauola_125.root
TTFH_MC_SUSYGluGluToHToTauTau_M-130_8TeV-pythia6-tauola_116.root
TTFH_MC_SUSYGluGluToHToTauTau_M-130_8TeV-pythia6-tauola_117.root
TTFH_MC_SUSYGluGluToHToTauTau_M-130_8TeV-pythia6-tauola_110.root

The Error it through is :
Code:
Error in <TFile::TFile>: file /filePATH/TTFH_MC_SUSYGluGluToHToTauTau_M-130_8TeV-pythia6-tauola*root does not exist

I think I should be able to grab all files using top script, NO?

thanks for suggestions,
emily
# 2  
Old 10-10-2014
* does not expand inside double quotes.

Code:
./main "$FILENAME"*.root $LUMIFILE  $CONFIGDEFAULTFILE

These 2 Users Gave Thanks to Corona688 For This Post:
# 3  
Old 10-10-2014
This can be easily mistaken after you have seen something like this

Code:
find -name "*.jpg"

which it does actually expands. The find command does not expand the same way the shell does.
This User Gave Thanks to Kibou For This Post:
# 4  
Old 10-10-2014
Quote:
Originally Posted by Kibou
This can be easily mistaken after you have seen something like this

Code:
find -name "*.jpg"

which it does actually expands. The find command does not expand the same way the shell does.
There is a HUGE difference between:
Code:
find . -name "*.jpg"

and:
Code:
find . -name *.jpg

but, if there are no files with a name ending with the string ".jpg" in the directory where you invoke these commands, the results will be identical.

In the 1st case, the shell will not perform any pattern matching based on the asterisk because it is quoted. Therefore, find will receive *.jpg as an argument from the shell and find will use that argument to match against all filenames in the file hierarchy rooted in the current directory.

In the 2nd case, the shell will expand *.jpg into a list of all of the files in the current directory that match that pattern and pass one argument to find for each matched file. If there is no match, the results will be the same as if the argument had been quoted. If one filename matched, find will only look for files with the same name as the file found in the current directory in the file hierarchy rooted in the current directory. If two or more files match, you'll get a syntax error from find.
These 2 Users Gave Thanks to Don Cragun For This Post:
# 5  
Old 10-10-2014
Sample output,

Code:
kibou@laptop:~$ touch /tmp/file{1..5}
kibou@laptop:~$ find /tmp/ -name file*
find: Las rutas deben preceder la expresión: file1
Uso: find [-H] [-L] [-P] [-Onivel] [-D help|tree|search|stat|rates|opt|exec] [ruta...] [expresión]
kibou@laptop:~$ find /tmp/ -name "file*"
/tmp/file3
/tmp/file5
/tmp/file4
/tmp/file1
/tmp/file2
kibou@laptop:~$ find /tmp/ -name "file*" | sort -r # I'll just add this so it looks nicer :)
/tmp/file5
/tmp/file4
/tmp/file3
/tmp/file2
/tmp/file1

This User Gave Thanks to Kibou For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Error while reading variable from a file in perl script

I have a file abc.ini and declared many variables in that file, one of the variable(DBname) value I am trying to read in my perl script but getting error. File abc.ini content # database name DBname =UATBOX my $ex_stat; my $cmd_output; $ex_stat = "\Qawk '/^DBname/{print... (2 Replies)
Discussion started by: Devesh5683
2 Replies

2. Shell Programming and Scripting

Trouble with variable assignment and reading in shell scripting

Hi, I have an inputfile with some table names in it. For ex: t_arnge t_profl t_fac I need a script which reads the line one by one and need to assign to some dynamic variable. If to explain the above example: i need some a=table_name1 table_name1=t_arnge in first time and... (4 Replies)
Discussion started by: Ravindra Swan
4 Replies

3. Shell Programming and Scripting

Error while reading from a file in shell script

Hi All, I'm writing a script to read a file line by line and then perform awk function on it. I am getting an error . My file has one name in it "James". I'm expecting my o/p to be youareJamesbond James ./users.sh: line 7: =: command not found #script to read file line by line #adding... (5 Replies)
Discussion started by: Irishboy24
5 Replies

4. Shell Programming and Scripting

Reading comma separated variable into other variables in shell script

Hi, In shell script, I have a variable var = xyz, inn, day, night, calif ....n and I would like to read them in to var1 = xzy, var2 = inn, var3= day, var4 = night....var. probably in a loop. I would like to read the variables until end of the line. Comma is the delimiter and there's no comma at... (3 Replies)
Discussion started by: suryaemlinux
3 Replies

5. Shell Programming and Scripting

Reading multi lines variable using shell script

Hi, I am using #!/bin/sh shell. I have a variable which contains multi line data. I want to read that variable line by line. Can someone post the code to read the multi line variable line by line? Any help is much appreciated. (2 Replies)
Discussion started by: gupt_ash
2 Replies

6. Shell Programming and Scripting

reading environment variable from awk script

Hi All, I am using SunSolaris machine. I need to get the value of environment variable from awk begin. Then use that value as the start number of a sequence and use that in my print statement. But it is not reading the value from environment variable. I have tried the following: ... (5 Replies)
Discussion started by: prashas_d
5 Replies

7. Shell Programming and Scripting

error in passing a variable to sqlplus from a shell script

hi, I am using a shell script from where i will be conecting to sqlplus.. i am having a problem in passing a variable to sqlplus query.. i will be assigning the variable in the unix environment..whenever i am trying to pass a variable having the contents greater than 2500 characters, i am... (3 Replies)
Discussion started by: kripssmart
3 Replies

8. Shell Programming and Scripting

Reading a path (including ref to shell variable) from file

Hi! 1. I have a parameter file containing path to log files. For this example both paths are the same, one is stated directly and the second using env variables. /oracle/admin/orcl/bdump/:atlas:trc:N ${ORACLE_BASE}/admin/${ORACLE_SID}/bdump/:${ORACLE_SID}:trc:N 2. I try to parse the path... (1 Reply)
Discussion started by: lojzev
1 Replies

9. UNIX for Advanced & Expert Users

Please Help!! Reading a string of text with concurrent spaces into a shell variable

Please Help!! Here is a very simplistic example of what I am trying to accomplish. I need what I have inbetween the quotes to be read into the shell variable. x="This is fun" echo $x The results of x from the above expression is: This is fun Notice the unix takes out the... (1 Reply)
Discussion started by: mjs3221
1 Replies

10. UNIX for Dummies Questions & Answers

Reading input to create a variable in a script?

I would like to prompt for input and then use it as a variable in a script. Something like this. #!/bin/ksh echo "What is your name?: \c" read response echo "Your name is $reply" >file.txt done exit 0 What am I missing? Thanks, (7 Replies)
Discussion started by: darthur
7 Replies
Login or Register to Ask a Question