Unix/Linux Go Back    


Shell Programming and Scripting BSD, Linux, and UNIX shell scripting Post awk, bash, csh, ksh, perl, php, python, sed, sh, shell scripts, and other shell scripting languages questions here.

': not a valid identifier

Shell Programming and Scripting


Closed    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 09-08-2008
script123 script123 is offline
Registered User
 
Join Date: Sep 2008
Last Activity: 4 April 2009, 2:47 PM EDT
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
': not a valid identifier

I am trying to write a bash script. I am able to do simple things like pass arguments, assign variables and echo the results. However, when I try to declare and array or anything a little more complicated I get
': not a valid identifier

Here is my code so far:

#!/bin/bash
echo start t
declare -a ARRAY
echo end t

And when I execute the script I get:

start t
': not a valid identifier
end t

My plan is to make a script that reads a file on line at a time and output's only part of each line to another file. It doesn't seem like it should be hard. But I can't get anything to work.
Sponsored Links
    #2  
Old Unix and Linux 09-08-2008
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
 
Join Date: Feb 2004
Last Activity: 3 December 2016, 11:52 AM EST
Location: NM
Posts: 10,875
Thanks: 457
Thanked 985 Times in 916 Posts
It looks like t is evaluating to :

When you write code, and you are new to coding, or to a system, you need to be careful of lowercase short variable names or words outside of quotes...

Code:
$#!/bin/bash
echo "start t"
declare -a ARRAY

echo "end t"
exit 0

Also start your script with a first line that is a shebang - in your case #!/bin/bash or maybe /usr/bin/sh. This makes the script ALWAYS run under the same shell. You may think this is a waste, but it is important. End with exit 0.
Sponsored Links
    #3  
Old Unix and Linux 09-08-2008
Ikon's Unix or Linux Image
Ikon Ikon is offline Forum Advisor  
Computer Geek
 
Join Date: Jul 2008
Last Activity: 15 January 2015, 10:57 AM EST
Location: Frederick, MD
Posts: 748
Thanks: 4
Thanked 11 Times in 10 Posts
You probabally could use sed or awk or something else depending on what the file looks like.
    #4  
Old Unix and Linux 09-08-2008
script123 script123 is offline
Registered User
 
Join Date: Sep 2008
Last Activity: 4 April 2009, 2:47 PM EDT
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Jim:
Thanks for your input. However, putting the text in quotes produces the same results.

Adding the exit 0 line will only shut my session down.

Ikon: Thanks. I'll look into usin sed or awk.
Sponsored Links
    #5  
Old Unix and Linux 09-08-2008
Ikon's Unix or Linux Image
Ikon Ikon is offline Forum Advisor  
Computer Geek
 
Join Date: Jul 2008
Last Activity: 15 January 2015, 10:57 AM EST
Location: Frederick, MD
Posts: 748
Thanks: 4
Thanked 11 Times in 10 Posts
Try:

Code:
#!/bin/bash
echo "start t"
set -a ARRAY
echo "end t"

Sponsored Links
    #6  
Old Unix and Linux 09-08-2008
script123 script123 is offline
Registered User
 
Join Date: Sep 2008
Last Activity: 4 April 2009, 2:47 PM EDT
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Thanks Icon! That worked. Do you have any idea why I couldn't use declare?
Sponsored Links
    #7  
Old Unix and Linux 09-08-2008
Ikon's Unix or Linux Image
Ikon Ikon is offline Forum Advisor  
Computer Geek
 
Join Date: Jul 2008
Last Activity: 15 January 2015, 10:57 AM EST
Location: Frederick, MD
Posts: 748
Thanks: 4
Thanked 11 Times in 10 Posts
On our HP-UX servers we use korn shell and had same problem.
Sponsored Links
Closed

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
awk command - not a valid identifier message venhart Shell Programming and Scripting 6 09-12-2011 01:37 PM
is not an identifier Phuti Shell Programming and Scripting 2 11-11-2010 10:37 AM
is not an identifier error svajhala Shell Programming and Scripting 13 06-15-2010 08:12 PM
not an identifier gyanibaba Shell Programming and Scripting 3 02-09-2010 02:59 AM
-sh: is not an identifier megh Solaris 4 05-03-2009 07:10 PM



All times are GMT -4. The time now is 05:49 PM.