The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Operating Systems > SUN Solaris
.
google unix.com



SUN Solaris The Solaris Operating System, usually known simply as Solaris, is a free Unix-based operating system introduced by Sun Microsystems .

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Global variable declaration in shell scripting susilgandhi Shell Programming and Scripting 1 02-06-2008 12:59 AM
Can give the input to prompt using shell script Vaibhav Agarwal Shell Programming and Scripting 2 11-01-2007 03:26 AM
Array Declaration and For Loop 33junaid Shell Programming and Scripting 4 09-15-2007 04:16 PM
Size of an array in sh shell script trivektor Shell Programming and Scripting 1 09-28-2006 11:01 PM
how to give a variable to a command in shell script... santy Shell Programming and Scripting 6 08-17-2006 11:53 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 02-11-2008
naree naree is offline
Registered User
  
 

Join Date: Feb 2008
Posts: 81
i cannot give array declaration in shell script

Dear all,
i m unable to give array decalartion in solaris Operating system shell script

and script was so.sh

declare -a bull[90]

for i in 1 2 3 4 5 6 7 8 9
do

bull[$i]=$i
echo "${bull[$i]}"

done

it is throwing an error called


so.sh: declare: not found
so.sh: bull[1]=1: not found
so.sh: bad substitution

Sir if u cud help ragrding this issue
  #2 (permalink)  
Old 02-11-2008
System Shock's Avatar
System Shock System Shock is offline Forum Advisor  
Registered User
  
 

Join Date: May 2006
Location: Tau Ceti V
Posts: 521
For starters, "declare" means nothing to the shell.
If you are going to be using arrays, I'd suggest you switch to the korn shell, which I find more efficient in handling arrays than any other shell. In korn shell, you set an array with:
Code:
# set -A bull 1 2 3 4 5 6 7 8 9
This sets array "bull" with numbers 1 through 9 in spots 0 through 8, respectively.
  #3 (permalink)  
Old 02-11-2008
fpmurphy's Avatar
fpmurphy fpmurphy is offline Forum Staff  
Moderator
  
 

Join Date: Dec 2003
Location: Florida
Posts: 1,924
Actually "declare -a" is supported in the bash shell.

If the bash shell is available on your system, then the following should work (you may need to change "/usr/local/bin/bash" to point to wherever bash is installed on your system)

Code:
#!/usr/local/bin/bash

declare -a bull

for i in 1 2 3 4 5 6 7 8 9
do
    bull[$i]=$i
    echo "${bull[$i]}"
done
You can also perform the loop as follows

Code:
for  (( i=1; i < 10; i++ ))
do
    bull[$i]=$i
    echo "${bull[$i]}"
done
  #4 (permalink)  
Old 02-12-2008
naree naree is offline
Registered User
  
 

Join Date: Feb 2008
Posts: 81
Cannot create and declare an array and substitute the values in bash shell

Sir i m unable to do .. above mentioned in a script ..

It shooting same old error.

ara.sh: declare: not found
ara.sh: syntax error at line 3: `(' unexpected

ara.sh is

declare -a bull[10]

for (( i=1; i < 10; i++ ))
do
bull[$i]=$i
echo "${bull[$i]}"
done
  #5 (permalink)  
Old 02-12-2008
fpmurphy's Avatar
fpmurphy fpmurphy is offline Forum Staff  
Moderator
  
 

Join Date: Dec 2003
Location: Florida
Posts: 1,924
What shell are you using?
  #6 (permalink)  
Old 02-12-2008
naree naree is offline
Registered User
  
 

Join Date: Feb 2008
Posts: 81
i cannot give array declaration in shell scripting

Sir i m using BASH shell in solaris..
  #7 (permalink)  
Old 02-12-2008
naree naree is offline
Registered User
  
 

Join Date: Feb 2008
Posts: 81
Quote:
Originally Posted by fpmurphy View Post
What shell are you using?
Sir i m using Bash Shell in which i m unable to work out this code..
Closed Thread

Bookmarks

Tags
solaris

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 10:39 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0