function not see variable in script


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers function not see variable in script
# 8  
Old 09-10-2010
Hi.

No. I used ${1:-file1} just because I got too lazy typing the filename in every time I ran the script! It means, if no filename is given on the command line, use a file called file1 instead.

So, apart from the ${x} versus x thing, there was really nothing wrong with your script!
# 9  
Old 09-10-2010
Quote:
Originally Posted by ShinTec
O
Scottn does this line
Code:
done < ${1:-file1}

tell the script to look in the current directory or am i way off
This reads "if no argument($1 not set or null) is passed use file1 as the default". If file1 is not in the current working directory then it will fail unless you pass it.

---------- Post updated at 20:50 ---------- Previous update was at 20:46 ----------

Quote:
Originally Posted by scottn
So, apart from the ${x} versus x thing, there was really nothing wrong with your script!
actually there was a problem with the regex -- . was matching all characters. some how this was siliently fixed in your code Smilie
# 10  
Old 09-10-2010
Hi.

A minor note: for the type of character class that you wanted to use:
Quote:
Originally Posted by ShinTec
...echo ${1} | grep -E '[:digit:]+.[:digit:]+' ...
You need to use an extra set of brackets:
Code:
       Finally,  certain  named  classes  of  characters are predefined within
       bracket expressions, as follows.  Their names are self explanatory, and
       they   are   [:alnum:],  [:alpha:],  [:cntrl:],  [:digit:],  [:graph:],
       [:lower:], [:print:], [:punct:], [:space:], [:upper:], and  [:xdigit:].
       For  example,  [[:alnum:]]  means  [0-9A-Za-z],  except the latter form
       depends upon the C locale and the ASCII character encoding, whereas the
       former  is  independent  of  locale  and character set.  (Note that the
       brackets in these class names are part of the symbolic names, and  must
       be  included  in  addition  to  the  brackets  delimiting  the  bracket
       expression.)

-- excerpt from man grep, q.v.

cheers, drl
# 11  
Old 09-10-2010
Quote:
Originally Posted by frank_rizzo
This reads "if no argument($1 not set or null) is passed use file1 as the default". If file1 is not in the current working directory then it will fail unless you pass it.

---------- Post updated at 20:50 ---------- Previous update was at 20:46 ----------



actually there was a problem with the regex -- . was matching all characters. some how this was siliently fixed in your code Smilie
Oh yes, the regex... Smilie (not sure what you mean by silently)

But apart from that...

Last edited by Scott; 09-10-2010 at 10:58 PM..
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to pass variable from one function to another function?

updateEnvironmentField() { linewithoutquotes=`echo $LINE | tr -d '"'` b() } I want to pass variable named $linewithoutquotes to another method called b(), which is called from updateEnvironmentField() method. How to do the above requirement with shell script (1 Reply)
Discussion started by: pottic
1 Replies

2. Shell Programming and Scripting

Shell script to pass the config file lines as variable on the respective called function on a script

I want to make a config file which contain all the paths. i want to read the config file line by line and pass as an argument on my below function. Replace all the path with reading config path line by line and pass in respective functions. how can i achieve that? Kindly guide. ... (6 Replies)
Discussion started by: sadique.manzar
6 Replies

3. Shell Programming and Scripting

Will files, creaetd in one function of the same script will be recognized in another function?

Dear All. I have a script, which process files one by one. In the script I have two functions. one sftp files to different server the other from existing file create file with different name. My question is: Will sftp function recognize files names , which are created in another... (1 Reply)
Discussion started by: digioleg54
1 Replies

4. Shell Programming and Scripting

Passing variable value in a function to be used by another function

Hello All, I would like to ask help from you on how to pass variable value from a function that has been called inside the function. I have created below and put the variables in " ". Is there another way I can do this? Thank you in advance. readtasklist() { while read -r mod ver... (1 Reply)
Discussion started by: aderamos12
1 Replies

5. Shell Programming and Scripting

Pass a variable string in To_Date Oracle function in shell script

Hello, I am trying to execute an SQL query from shell script. A part of script is something like this: fromDate=`echo $(date +"%F%T") | sed "s/-//g" | sed "s/://g"` $ORACLE_HOME/sqlplus -s /nolog <<EOD1 connect $COSDBUID/$COSDBPWD@$COSDBSID spool... (4 Replies)
Discussion started by: sanketpatel.86
4 Replies

6. Shell Programming and Scripting

How to pass a function with a variable parameter into another variable?

Hello again :) Am currently trying to write a function which will delete a record from a file. The code currently looks as such: function deleteRecord() { clear read -p "Please enter the ID of the record you wish to remove: " strID ... (2 Replies)
Discussion started by: U_C_Dispatj
2 Replies

7. Shell Programming and Scripting

SHELL SCRIPT Function Calling Another Function Please Help...

This is my function which is creating three variables based on counter & writing these variable to database by calling another function writeRecord but only one record is getting wrote in DB.... Please advise ASAP...:confused: function InsertFtg { FTGSTR="" echo "Saurabh is GREAT $#" let... (2 Replies)
Discussion started by: omkar.sonawane
2 Replies

8. Shell Programming and Scripting

Passing global variable to a function which is called by another function

Hi , I have three funcions f1, f2 and f3 . f1 calls f2 and f2 calls f3 . I have a global variable "period" which i want to pass to f3 . Can i pass the variable directly in the definition of f3 ? Pls help . sars (4 Replies)
Discussion started by: sars
4 Replies

9. Shell Programming and Scripting

shell script receiving variable and doing mathematical function

Hello, Please help for the following scenario: 1. Shell Scipt should receive 2 variables values (say a and b). 2. Within shell script, there should be division of those numbers (a/b). 3. The result should be whole number i.e. in case the result comes out to be 9.4, it should be returned as... (3 Replies)
Discussion started by: damansingh
3 Replies

10. UNIX for Dummies Questions & Answers

passing a variable inside a variable to a function

I would like to know how to pass a variable inside a variable to a function. sample code below -------------- for x in 1 9 do check_null $C$x ##call function to check if the value is null if then echo "line number:$var_cnt,... (2 Replies)
Discussion started by: KingVikram
2 Replies
Login or Register to Ask a Question