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-27-2012, 06:50 AM   #1
ankitpandey
Member
 
Registered: Jan 2012
Location: Mumbai
Posts: 63

Rep: Reputation: Disabled
unable to declare array in Solaris


Hello Team,

While trying to declare Array in Solaris, it is throwing "declare: not found" error. Can you please suggest.

Code:
$ echo $SHELL
/bin/bash
$ declare -a vt_tbl_array
declare: not found
$
Thanks,
Ankit
 
Old 12-27-2012, 07:09 AM   #2
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,863
Blog Entries: 1

Rep: Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869
Try this:
Code:
$ echo $BASH_VERSION
 
Old 12-27-2012, 07:17 AM   #3
ankitpandey
Member
 
Registered: Jan 2012
Location: Mumbai
Posts: 63

Original Poster
Rep: Reputation: Disabled
Code:
$ echo $BASH_VERSION

$
For my username korn shell is default, i was trying to run that on bash by keeping it on top line of script. I hope that runs it on bash irrespective of what shell is defined for me right ?

Above result gives no result.
 
Old 12-27-2012, 07:25 AM   #4
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,863
Blog Entries: 1

Rep: Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869
Now is it a script, or dialogue? If script, then begin it with a she-bang:

Code:
cat test.sh
#!/bin/bash
echo $BASH_VERSION
ps
./test.sh
3.2.0(1)-release
     PID    TTY  TIME CMD
  848044  pts/3  0:00 -bash 
 1003718  pts/3  0:00 ps 
 1073356  pts/3  0:00 /bin/bash ./test.sh
 
Old 12-27-2012, 07:29 AM   #5
ankitpandey
Member
 
Registered: Jan 2012
Location: Mumbai
Posts: 63

Original Poster
Rep: Reputation: Disabled
Code:
$ cat test1.sh
#!/bin/bash
echo $BASH_VERSION
ps

$ sh test1.sh

   PID TTY         TIME CMD
 11741 pts/16      0:00 sh
  1751 pts/16      0:00 ksh
 11742 pts/16      0:00 ps
$
No Luck.
 
Old 12-27-2012, 07:33 AM   #6
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,863
Blog Entries: 1

Rep: Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869
Be careful, the following commands are different:
Code:
1: sh test1.sh
2: ./test1.sh # don't forget chmod +x test1.sh beforehand
You should try the second one. Also check where is your bash actually is: command which bash

Last edited by NevemTeve; 12-27-2012 at 07:35 AM.
 
1 members found this post helpful.
Old 12-27-2012, 07:43 AM   #7
ankitpandey
Member
 
Registered: Jan 2012
Location: Mumbai
Posts: 63

Original Poster
Rep: Reputation: Disabled
Thanks, i missed that.

Code:
$./test1.sh
3.00.16(1)-release
   PID TTY         TIME CMD
 17726 pts/16      0:00 test1.sh
  1751 pts/16      0:00 ksh
 17727 pts/16      0:00 ps

$ which bash    
/usr/bin/bash
 
Old 12-27-2012, 07:51 AM   #8
ankitpandey
Member
 
Registered: Jan 2012
Location: Mumbai
Posts: 63

Original Poster
Rep: Reputation: Disabled
It's Working !!... and it has resolved the problem... i was running it as sh <script_name>.sh, but when i ran it as ./<script_name>.sh it worked.

Can you please explain why it is differnt and how can i test it manually ? By this was i can only test in by putting this in script, i was trying to test each line by line, but that takes the default shell. Korn shell dosen't support array ?

Thanks
 
Old 12-27-2012, 08:00 AM   #9
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,863
Blog Entries: 1

Rep: Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869
"sh scriptfile" means: dear sh, execute this script; while "./scriptfile" means: dear kernel, find out (from the first line) what program interprets this scripts, then start that interpreter (bash, in this case, but could have been anything else like perl, php, python etc), and give it 'scriptfile' as parameter -- the the interpreter opens, reads and executes 'scriptfile'.

Last edited by NevemTeve; 12-27-2012 at 11:20 AM. Reason: typo
 
1 members found this post helpful.
Old 12-27-2012, 08:05 AM   #10
ankitpandey
Member
 
Registered: Jan 2012
Location: Mumbai
Posts: 63

Original Poster
Rep: Reputation: Disabled
Thanks NavemTeve.. for this clarification.
 
Old 12-27-2012, 04:19 PM   #11
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Arch + Xfce
Posts: 6,852

Rep: Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037
Notice too that the first line of the shebang is "#", which means that when you give the file to a shell as an argument, it will be ignored as a comment.

The shebang only has special meaning when the file is executed directly, as explained above.
 
2 members found this post helpful.
  


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
Bash array manipulation on solaris nano2 Solaris / OpenSolaris 11 12-04-2011 06:54 AM
[SOLVED] Can't declare an array of pointers to member functions KenJackson Programming 3 09-03-2010 03:08 PM
Unable to declare a variable in Cygwin erora Linux - Newbie 4 01-21-2010 03:27 PM

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

All times are GMT -5. The time now is 09:37 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