': not a valid identifier | Unix Linux Forums | Shell Programming and Scripting

  Go Back    


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

': not a valid identifier

Shell Programming and Scripting


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 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 09-08-2008
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
 
Join Date: Feb 2004
Last Activity: 19 October 2014, 10:32 PM EDT
Location: NM
Posts: 10,236
Thanks: 281
Thanked 802 Times in 746 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 09-08-2008
Ikon's Avatar
Ikon Ikon is offline Forum Advisor  
Computer Geek
 
Join Date: Jul 2008
Last Activity: 10 July 2013, 11:06 AM EDT
Location: Frederick, MD
Posts: 748
Thanks: 4
Thanked 10 Times in 9 Posts
You probabally could use sed or awk or something else depending on what the file looks like.
    #4  
Old 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 09-08-2008
Ikon's Avatar
Ikon Ikon is offline Forum Advisor  
Computer Geek
 
Join Date: Jul 2008
Last Activity: 10 July 2013, 11:06 AM EDT
Location: Frederick, MD
Posts: 748
Thanks: 4
Thanked 10 Times in 9 Posts
Try:

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

Sponsored Links
    #6  
Old 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 09-08-2008
Ikon's Avatar
Ikon Ikon is offline Forum Advisor  
Computer Geek
 
Join Date: Jul 2008
Last Activity: 10 July 2013, 11:06 AM EDT
Location: Frederick, MD
Posts: 748
Thanks: 4
Thanked 10 Times in 9 Posts
On our HP-UX servers we use korn shell and had same problem.
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 12:37 PM
is not an identifier Phuti Shell Programming and Scripting 2 11-11-2010 09:37 AM
is not an identifier error svajhala Shell Programming and Scripting 13 06-15-2010 07:12 PM
not an identifier gyanibaba Shell Programming and Scripting 3 02-09-2010 01:59 AM
-sh: is not an identifier megh Solaris 4 05-03-2009 06:10 PM



All times are GMT -4. The time now is 07:21 AM.