LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 12-04-2007, 01:23 AM   #1
champak
LQ Newbie
 
Registered: Nov 2007
Posts: 20

Rep: Reputation: 0
Solaris and redhat difference in bash scripting


Hi..
Anything wrong with the following line in my script?

Code:
logArray=$(find "$1" -type f|grep -v bak)
This works fine in Redhat linux. But in Solaris I get

Quote:
Job.sh: syntax error at line 96: `logArray=$' unexpected
Is there in any difference in redhat bash & solaris bash..

Last edited by champak; 12-04-2007 at 02:47 AM.
 
Old 12-04-2007, 02:06 AM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
are you actaully using bash? solaris using csh by default afair.
 
Old 12-04-2007, 02:15 AM   #3
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

Rep: Reputation: 244Reputation: 244Reputation: 244
Quote:
Originally Posted by champak View Post
Hi..
Anything wrong with the following line in my script?

Code:
logArray=$(find "$1" -type f|grep -v bak)
This works fine in Redhat linux. But in Solaris I get



Is there in any difference in redhat bash & solaris bash..

Thanks,
Ananth
in solaris, the default should be the bourne shell if i am not wrong. you can use
Code:
#!/usr/bin/bash
logarray=$(find ...)
in bourne shell, you can use backticks
Code:
logarray=`find...`
 
Old 12-04-2007, 02:53 AM   #4
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: Mint, Armbian, NetBSD, Puppy, Raspbian
Posts: 3,515

Rep: Reputation: 239Reputation: 239Reputation: 239
in solaris, a default shell script runs with /bin/sh
on linux a /bin/sh shell is actually /bin/bash
and very annoyingly is not as compatible as it says it is.

So a linux /bin/sh is not actually a valid /bin/sh
script on another system (solaris at least).

in Solaris I would advise that you use /bin/ksh which will run most bash scripts.

IMHO korn is a much better scripting shell anyhow.

Last edited by bigearsbilly; 12-04-2007 at 02:55 AM.
 
Old 12-04-2007, 03:22 AM   #5
champak
LQ Newbie
 
Registered: Nov 2007
Posts: 20

Original Poster
Rep: Reputation: 0
Hi...
Thanks acid_kewpie and ghostdog74
In my target system the default is configured to be ksh.
But Im using Bash to execute the script.(#!/usr/bin/bash)

The script was fine in Redhat.
Should I be replacing $(cmds) to `(cmds)` to make it work in Solaris?

Why it doesn work in Solaris?



Thanks.
 
Old 12-04-2007, 03:25 AM   #6
champak
LQ Newbie
 
Registered: Nov 2007
Posts: 20

Original Poster
Rep: Reputation: 0
Thanks bigearsbilly.
I dint see your reply before posting the previous quick reply
 
Old 12-04-2007, 04:02 AM   #7
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

Rep: Reputation: 244Reputation: 244Reputation: 244
Quote:
Originally Posted by champak View Post
Hi...
Thanks acid_kewpie and ghostdog74
In my target system the default is configured to be ksh.
But Im using Bash to execute the script.(#!/usr/bin/bash)

The script was fine in Redhat.
Should I be replacing $(cmds) to `(cmds)` to make it work in Solaris?

Why it doesn work in Solaris?



Thanks.
you can try (for the $() syntax ). Later version of Solaris comes with bash.

Code:
# bash myscript.sh
or if you have defined the shebang as #!/usr/bin/bash
then just

/path/myscript.sh
 
Old 12-04-2007, 04:09 AM   #8
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: Mint, Armbian, NetBSD, Puppy, Raspbian
Posts: 3,515

Rep: Reputation: 239Reputation: 239Reputation: 239
the $(command) works in /bin/ksh


I would just put

#!/bin/ksh


for each script and try it.
 
Old 12-04-2007, 04:39 AM   #9
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris 11.4, Oracle Linux, Mint, Debian/WSL
Posts: 9,789

Rep: Reputation: 492Reputation: 492Reputation: 492Reputation: 492Reputation: 492
The $(command) works under Solaris with most shells including:

/usr/xpg4/bin/sh (POSIX compliant shell)
/bin/ksh (ksh88)
/usr/dt/bin/dtksh (old CDE ksh93 with X11 support)
/bin/ksh93 (the latest ksh)
/bin/bash
/bin/zsh

It doesn't works with /bin/sh which is not POSIX compliant but kept here for upward compatibility requirements (POSIX shell can break legacy /bin/sh scripts).

As bigearsbilly suggests, the preferred shell under Solaris is ksh (and ksh93 when available).
 
Old 12-04-2007, 04:39 PM   #10
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,358

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
I also strongly advise deciding/finding out which shell you ought to use in prod eg ksh and using the same for dev.
In the same spirit, always use an explicit shell invocation eg
#!/bin/ksh
It's amazing how often the default shell in any given env is NOT the same as yours....
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How much difference is there between Solaris 10 and various linux versions? rob5044 Linux - General 4 12-01-2006 08:36 AM
difference between linux and solaris ganeshjeyaraman Linux - General 8 06-19-2006 06:38 AM
difference between shell scripting and c language gadekishore Linux - Software 5 10-17-2005 06:33 AM
what is the difference between Scripting language and Normal Languages ? indian Programming 5 03-15-2005 03:10 PM
Solaris vs. Linux - What's the difference? zzzt Linux - General 7 10-20-2003 01:12 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:26 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration