Re: Problem with a variable in my short shell script (151 Views)
Reply
Frequent Advisor
Chris Elmore
Posts: 51
Registered: ‎05-07-2002
Message 1 of 7 (151 Views)
Accepted Solution

Problem with a variable in my short shell script

Aloha Folks,

I am having some trouble with a basic shell script I am drafting and the error that is produced when I execute the script is this:

./Trp_Extract.sh[2]: TROUPERS^M: This is not an identifier.

The first 2 lines of the shell script sets a variable:

TROUPERS=/home/TROUPERS
export TROUPERS


The file is set to 777. Any ideas folks? Thanks in advance.

Very Respectfully,
Chris Elmore
"Life is love and love is life"
Acclaimed Contributor
A. Clay Stephenson
Posts: 17,825
Registered: ‎07-16-1998
Message 2 of 7 (151 Views)

Re: Problem with a variable in my short shell script

Let the very 1st line of your script be:
#!/usr/bin/sh

export TROUPERS=/home/TROUPERS

It's always wise to use a "shbang" line in a script so that the system knows which executable to run your script against (POSIX/Bourne/Korn shell, perl, awk, ...).
If it ain't broke, I can fix that.
Frequent Advisor
Chris Elmore
Posts: 51
Registered: ‎05-07-2002
Message 3 of 7 (151 Views)

Re: Problem with a variable in my short shell script

Aloha Mr. Stephenson,

Good to chat with you again! I tried using the shbang and this is what I get:

interpreter "/usr/bin/sh" not found
sh: Trp_Extract.sh: not found.

Any ideas what I'm doing wrong?

v/r,
Chris
"Life is love and love is life"
Frequent Advisor
Chris Elmore
Posts: 51
Registered: ‎05-07-2002
Message 4 of 7 (151 Views)

Re: Problem with a variable in my short shell script

Aloha Clay,

Your export syntax was spot on! The variables are setting correctly now. I was going off of an older install doc and the format must not be compatible with our newer OS. Thanks a bunch! I still can't get the shbang to set though. Any ideas!

Your the BEST!

v/r,
Chris
"Life is love and love is life"
Honored Contributor
Matti_Kurkela
Posts: 6,271
Registered: ‎12-02-2001
Message 5 of 7 (151 Views)

Re: Problem with a variable in my short shell script

Did you edit this script on a MS-Windows computer and then moved it to a HP-UX?

The '^M' suggests that there may be Windows-style end-of-line characters in the script that are confusing the shell.

If you use FTP to transfer the script from MS-Windows to HP-UX, remember to use ASCII transfer mode when transferring scripts. This will handle the line ending character conversion automatically.

Your script is apparently named "Trp_Extract.sh". Please run "dos2ux Trp_Extract.sh" to convert the line ending characters to Unix style.

By the way, it's a very bad habit to set file permissions to 777 whenever there's a problem. Someone may add a few commands of his/her own into your script... and when you run it, they are executed using your identity. A smart intruder uses this to build him/herself a back door to your account and then restore your original script.

755 is enough for a script. If it needs to be maintained by a group of people, then 775. Never 777.

MK
MK
Honored Contributor
Patrick Wallek
Posts: 13,787
Registered: ‎06-21-2000
Message 6 of 7 (151 Views)

Re: Problem with a variable in my short shell script

Aloha,

/usr/bin/sh not found tells me that you might not be using HP-UX. If /usr/bin/sh were not on your HP-UX system then you would have a LOT of issues.

What operating system are you using?

Also, the line MUST be the very first line in the script and must be exactly as Clay posted it and it must start at the very beginning of the line.

# cat script
#!/usr/bin/sh
export VAR=somevalue
...
...
Frequent Advisor
Chris Elmore
Posts: 51
Registered: ‎05-07-2002
Message 7 of 7 (151 Views)

Re: Problem with a variable in my short shell script

Aloha Folks,

You folks are the best! Sure enough, the source of my woes was my new windows ssh ftp client that I was using... it was embedding garbage windows esc sequenses in all of my scripts. I fixed them in vi and all is well again. You folks are a real credit to the forums and I humbly thank you each and every one, for your rapid and thoughtful responses. Please take care folks!

Very Respectfully,
Chris Elmore
"Life is love and love is life"
The opinions expressed above are the personal opinions of the authors, not of HP. By using this site, you accept the Terms of Use and Rules of Participation.