Eliminate variable checking in a script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Eliminate variable checking in a script
# 1  
Old 12-03-2007
Eliminate variable checking in a script

RH Linux, $SHELL=/bin/ksh

I have a .profile which I source in as such --> . .profile

Whats happening is the variables are getting validated and generating errors.

for example

.profile
export foo=/to/the/moon

when I . .profile , I get

: not foundmyusername/.profile
or bad identifier

so the rest of my variables dont get set.

Is there a switch I can add to the top of the file ie

#!/bin/ksh -dontvaliddatemyvariables

thanks!
Bob
# 2  
Old 12-03-2007
What do you mean by "validating variables"?

I can't tell what is going on by what you have posted.
# 3  
Old 12-03-2007
Quote:
Originally Posted by porter
What do you mean by "validating variables"?

I can't tell what is going on by what you have posted.
when I source in a .profile, variables are somehow checked, and generating an error (listed)

contents of .profile

export foo=/a/location/that/dosnt/exist

when I source it it via . .profile
I get the error and other variables dont get set the script just craps out.
the error = : not foundmyusername/.profile
or bad identifier

this dosnt happen on other versions of UNIX - only some linuxes

so the interperter is checking of foos path is valid... if not if bombs out
# 4  
Old 12-03-2007
Is this for only some specific variables?

How did these variables get set when .profile was run at login time?

Personally I don't use "export foo=anything"

I split them into two....

Code:
foo=anything
export foo

because "foo=anything" is not a variable you can export.
# 5  
Old 12-03-2007
Quote:
Originally Posted by porter
Is this for only some specific variables?

How did these variables get set when .profile was run at login time?

Personally I don't use "export foo=anything"

I split them into two....

Code:
foo=anything
export foo

because "foo=anything" is not a variable you can export.
#############
I execute . profile manualy ie . .profile

you certianly can use export this way...

$ export VAR="Thanks for the reply"
$ echo $VAR
Thanks for the reply
# 6  
Old 12-03-2007
Quote:
Originally Posted by BMetelsky
you certianly can use export this way...
It's shell specific. I lean to to the pedantic portable side.

Give it a go, see if it makes a difference.

Why does an error stop other variables being set?

Personally I've never heard of variable checking in an assignment statement, how would the shell have any idea what was valid. If what you are saying is correct I could not do...

foo=/new/directory/to/create
mkdir -p $foo
# 7  
Old 12-03-2007
Quote:
Originally Posted by porter
It's shell specific. I lean to to the pedantic portable side.

Give it a go, see if it makes a difference.

Why does an error stop other variables being set?

Personally I've never heard of variable checking in an assignment statement, how would the shell have any idea what was valid. If what you are saying is correct I could not do...

foo=/new/directory/to/create
mkdir -p $foo
well... thanks for the sanity check. I seems there must have been some special (hidden) characters in the profile. I created a new file and the variables wourk as expected....

unreal-
Thanks
Bob
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Checking the variable in UNIX

Hi, I have a file abc.txt as ABC,TYU,1.2566 AHG,GJJ,1.898 hgh,FGA,1.854 My program is reading each line and storing the values variables base_cy, quo_cy, ra_amt Need to validate each of them as in: base_cy and quo_cy should be a 3 character alphabet among A-Z, if it is lower case ... (1 Reply)
Discussion started by: infyanurag
1 Replies

2. Shell Programming and Scripting

Script to eliminate files .rlogin

Hi guys, I'm try making to script for eliminate files rlogins. path1='/home/*' for i in `cat /etc/passwd |awk -F: '{print $6}'`; do if test "$i" = "$path1"; then echo $i cd $i if ; then echo "$i/.rhosts detectado"|mail -s "rhosts" root ... (14 Replies)
Discussion started by: nena_redbalon
14 Replies

3. UNIX for Dummies Questions & Answers

Checking the language variable

This is what I have just entered and received in return: # echo $LANG LANG: Undefined variable. How can this be? I was expecting something like en_US.utf8. Am using FreeBSD 8.2. (2 Replies)
Discussion started by: figaro
2 Replies

4. Shell Programming and Scripting

script to eliminate left and right fields and to get the ouput.

Hi Experts, I have a file as given below and want to filter out the filenames in it , by deleting left and right filds and to have the fllenames (There are spaces in the filename), Sun Jan 11 11:20:10 2009 1 0 /home/output/file2311_recent.list user1 user2 0 done Sun Jan 11 11:20:10 2009 1 0... (10 Replies)
Discussion started by: rveri
10 Replies

5. Shell Programming and Scripting

Shell script help to eliminate files of todays date

Hi I am very new to shell scripting and have written a script (below). However the directory I am searching will contain a file with a .trn extension each day which I want to eliminate. Each day the file extension overnight will change to trx, if this fails I want to know. Basically what I... (2 Replies)
Discussion started by: richM
2 Replies

6. Shell Programming and Scripting

checking variable has value - ksh

hi all, i have a shell (ksh) script where i am reading line by line from a grep command and i wanted to check if the grep command actually returned something or was null. i can do this by using -z : if ; then ..... but this forces me to do something when $myVariable is null when i... (3 Replies)
Discussion started by: cesarNZ
3 Replies

7. Shell Programming and Scripting

checking the value of the variable

Does anyone know the quick way to check if the variable contains only numeric characters, for example: A=123445 - correct B=#f123* - incorrect I am in ksh88i Thanks a lot for help -A (1 Reply)
Discussion started by: aoussenko
1 Replies

8. UNIX for Dummies Questions & Answers

ksh Checking if variable has 5 digits

How could I check if a numeric variable has 5 digits in KSH...I have a zipcode variable that I know will always be 5 digits, and I want to print out an error if it is less or more than 5 digits the problem is that I have it as: if ] but this won't work because the statement doesn't see 0001 as... (3 Replies)
Discussion started by: developncode
3 Replies

9. Shell Programming and Scripting

checking valid values in variable

I'm using the following in my script. if echo $cpuidle |/usr/bin/egrep ; then when I issue this statement it issues the value of the variable back to stdout which ends up in my output file. Is there a better way to write this? I'm using ksh on solaris 9. (3 Replies)
Discussion started by: MizzGail
3 Replies

10. Shell Programming and Scripting

checking a variable is within range

how can i check that a variable is between 0-100, like if i ask a user to input a number between 1-100 and i want to excute commands WHILE that number is between that range or else i will keep asking the user to make another input here's what i got #!/bin/bash echo "Guess my secret number... (2 Replies)
Discussion started by: Poison Ivy
2 Replies
Login or Register to Ask a Question