I feel stupid: declare not found in bash scripting?
I was anxious to get my feet wet, and I'm only up to my toes before I'm stuck...this seems very very easy but I'm not sure what I've done wrong. Below is the script and its output. What the heck am I missing?:cry:
______________________________________________________ #!/bin/bash declare -a PROD[0]="computers" PROD[1]="HomeAutomation" printf "${ PROD[*]}" _______________________________________________________ products.sh: 6: declare: not found products.sh: 8: Syntax error: Bad substitution mohtech |
I ran what you posted (but at the command line, not in a script, though that should make no significant difference), and got this:
Code:
-bash: ${ PROD[*]}: bad substitution And I got rid of the "bad substitution" problem when I removed the space which is between the ${ and the PROD on the printf line. Hope this helps. |
The previous poster identified your second problem.
As far as your first problem goes ... I am not a bash guru although I have written a number of bash scripts. So far I have found no need for declare statements. I suspect that you might not need it either. But if you do want to use it, the following does work: Code:
#!/bin/bash |
Hi.
As wjevans_7d1 wrote, removing the space when using the array name allows it to run. Here is a sample: Code:
#!/bin/bash Code:
% ./s1 |
Im having the similar problem as mohtech
It doesnt seem to recognise declare. I'm having the same problem with let and basic math code like incrementing a variable. Even creating an simple array gives me an error example names=( john thomas ) syntax error: `names=' unexpected I reckon I must have something disabled somewhere on the system. Im working on a beta server at work so I wasn't involved in the initial installation/setup. any ideas how I could remedy this? |
@brianhickey18: please start your own thread and give details of the script before the names= line. Software changes so it's seldom useful to revive a 3+ year old thread.
|
And, with that sage advice, old fossil thread now closed....
|
All times are GMT -5. The time now is 02:44 AM. |