Error due to unset variable - Solaris vs GNU Linux - Help needed


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users Error due to unset variable - Solaris vs GNU Linux - Help needed
# 1  
Old 02-04-2014
Error due to unset variable - Solaris vs GNU Linux - Help needed

Hi all,

I have a weird problem.
When i run the below code in SunOS and Linux i get different outputs

====
Code:
$ cat tst.ksh
#!/bin/ksh
 

echo "Abc" > $LOG_FILE
echo "Ret - $?"

=====

In Solaris
Code:
$ ./tst.ksh
Abc
Ret - 0

In GNU Linux
Code:
$ ./tst.ksh
./tst.ksh[6]: : cannot open
Ret - 1


The variable LOG_FILE is not set in both environments but it works in Solaris but not in GNU Linux.

Please let me know do i need a code change in GNU environment?

thanks.

Last edited by Scrutinizer; 02-04-2014 at 03:29 AM.. Reason: code tags
# 2  
Old 02-04-2014
how does it "work" in Solaris? What does it do? What shell is that, it's terrible!

Code:
$ ksh --version
  version         sh (AT&T Research) 1993-12-28 s+
$ ksh -s <<'__EOF__'
echo "Abc" > $LOG_FILE
echo "Ret - $?"
__EOF__

ksh[1]: : cannot open
Ret - 1

bash does the same thing: bash: line 1: $LOG_FILE: ambiguous redirect

Do you really need to cover the case where LOG_FILE is unset? Perhaps write a wrapper function:

Code:
mute@thedoctor:~$ echo "Hello" > "${LOG_FILE:-/dev/null}"
mute@thedoctor:~$ echo $?
0

there, success every time. Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Linux Commands needed for replacing variable number of spaces with a single , in a txt file

Hi I want to read a text file and replace various number of spaces between each string in to a single "," or any other character .Please let me know the command to do so. My input file is a txt file which is the output of a SQL table extract so it contains so many spaces between each column of the... (2 Replies)
Discussion started by: Hari Prasanth
2 Replies

2. UNIX for Dummies Questions & Answers

Unset environement variable

Hi, I have the following line in the script unset _SET_ENV_AA unset _SETENV but where I can check the value for this environement variable (2 Replies)
Discussion started by: stew
2 Replies

3. Shell Programming and Scripting

Unset variable with characters in value

I have a script with a $PASSWORD variable. I unset it right after using it, just to minimize the chance it could be left around for a snooper. That worked just fine... until I used a password with a value of "P@ssw0rd" Now, unset (even with -f, even with the variable enquoted) tells me: unset:... (1 Reply)
Discussion started by: jnojr
1 Replies

4. Shell Programming and Scripting

Converting from Linux bash (GNU) to Solaris script syntax errors

Original script written on CentOS 6.3 with GNU bash 4.1.2 Destination system is Solaris 9 with GNU bash 2.05 (not changeable by me) I have a script written on the linux side but now we need to provide a version to another site that "doesn't like linux". I've been going through changing the ] or... (13 Replies)
Discussion started by: oly_r
13 Replies

5. Shell Programming and Scripting

"Syntax Error sometimes due to corruption of variable value "

Hi , I have script as follows , #!/usr/bin/ksh -x if then alias echo="echo -e" fi MAX_ENTRIES=1024 nb_of_entries=`echo "$list_of_entries" | wc -w` # Set number of tables eval nb_of_tables=\`expr `expr $nb_of_entries / $MAX_ENTRIES` + 1 \` # Output the number of tables echo... (6 Replies)
Discussion started by: breezevinay
6 Replies

6. Shell Programming and Scripting

How do I define a particular dir in PATH variable and then unset that dir

How do I define a particular dir in front of PATH variable and then run some job and then at the end of job SET the PATH variable to original? in a script, WILL something like this work: ORIG_PATH=$PATH export PATH=/dir1/dir2:$PATH RUN SOME JOBS ..... unset PATH EXPORT... (2 Replies)
Discussion started by: Hangman2
2 Replies

7. UNIX for Advanced & Expert Users

how to unset the readonly variable

Hi All, May be this is a very simple question... $ b=8 $ readonly b $ echo $b 8 $ b=90 -bash: b: readonly variable $ unset b -bash: unset: b: cannot unset: readonly variable I m not able to change the readonly mode of variable b Please help me out.. Thanks Nidhi (2 Replies)
Discussion started by: Nidhi2177
2 Replies

8. Shell Programming and Scripting

Is there any way to set env variable in top level Makefile and unset when done

Hello I have compilation directory structure the top level Makefile is the one that contains all the sub directories I want to set in this Makefile env variable say : setenv OPTIMIZATION_LEVEL "1" and when all the sub directories done compiling it will set this variable to different lavel... (0 Replies)
Discussion started by: umen
0 Replies
Login or Register to Ask a Question