- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: `if' is not matched - message in shell script
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-27-2002 04:50 AM
тАО09-27-2002 04:50 AM
I am quite new to hp-ux and have the following problem:
I try using a simple if then else fi loop in a shell script under HP-UX 10.20
when I copy and past the code in a shell window everything works:
# if [ -f /home/vanadm/checkspace ]
> then
> echo yes
> else
> echo no
> fi
no
but when I try to run it as shell script (the code above saved in /home/vanadm/iftest) I get two errors:
1.
if the first script line contains a: #!/sbin/sh or #!/usr/bin/sh
I get:
# /home/vanadm/iftest
script interpreter "/usr/bin/sh" not found
sh: /home/vanadm/iftest: not found.
2.
if I remove the #!/xxx line the script is executed and returns:
# /home/vanadm/iftest
/home/vanadm/iftest: Syntax error at line 1 : `if' is not matched.
I am root, all files are rwxrwxrwx, and /usr/bin/sh _is_there_ ! ;-)
This `if' is not matched. drives me crazy. I tried the if [ xxx ] and the if test xxx syntax with no difference
I tried using multiple lines as above and a one-liner (if ; then ; else ; fi) - with no difference too
What specific Posix-Shell problem do I miss? (however, the problem remains the same using csh)
Thanks for any help
Christian Vollma
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-27-2002 05:02 AM
тАО09-27-2002 05:02 AM
Re: `if' is not matched - message in shell script
Can you put the entire listing of the script in a posting?
We can then have a look at the actual code. My personal style for testing conditions such as file existing is to use double square brackets - however I do not know if that affects the result you get.
Share and Enjoy! Ian
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-27-2002 05:10 AM
тАО09-27-2002 05:10 AM
Re: `if' is not matched - message in shell script
the unmatched if-error indicates that the shell cannot "see" the rest of the if- sentence, in particular not the "fi". It probably derives from your cut and paste where you probably paste some garbage into the script as well. Could you please try and write it manually in a fresh file?
regards,
John K.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-27-2002 05:11 AM
тАО09-27-2002 05:11 AM
Re: `if' is not matched - message in shell script
That is indeed strange ... the same script seems to work for me.
I've attached it. Can you execute it with
sh -x iftest.sh
and post the output ?
Regards,
Tom
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-27-2002 05:11 AM
тАО09-27-2002 05:11 AM
Re: `if' is not matched - message in shell script
Craig
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-27-2002 05:19 AM
тАО09-27-2002 05:19 AM
Re: `if' is not matched - message in shell script
whow, thats a response time!
The complete code is stored in /home/vanadm/iftest:
if [ -f /home/vanadm/checkspace ]
then
echo yes
else
echo no
fi
I have just tried double brackets an things changed to
' is not expected.rror at line 2 : `
(No mistyping, this is an exact paste from the shell window!)
There still seems to be a syntax problem!?!!
The problem does not depend on the condition I test, I tried several tests.
regs n thnx
Christian
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-27-2002 05:29 AM
тАО09-27-2002 05:29 AM
Re: `if' is not matched - message in shell script
I have just used Toms script in a fresh file (and my editor shows that there are no foreign characters or other garbage)
Here is the result:
# sh -x iftest.sh
+ [ -f /home/sys/checkspace ]
iftest.sh: test: A ] character is missing.
+
iftest.sh[4]: ^M: not found.
+ echo no
no
#
Any more ideas?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-27-2002 05:33 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-27-2002 05:37 AM
тАО09-27-2002 05:37 AM
Re: `if' is not matched - message in shell script
try to do a ux2dos on the script and try again.
dos2ux
regards
Yogeeraj
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-27-2002 05:40 AM
тАО09-27-2002 05:40 AM
Re: `if' is not matched - message in shell script
can you confirm that you actually typed the code manually?
Sorry, I have to ask, but your last response hints that you did not.
regards,
John K.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-27-2002 05:40 AM
тАО09-27-2002 05:40 AM
Re: `if' is not matched - message in shell script
sorry should have said "dos2ux"
dos2ux
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-27-2002 05:45 AM
тАО09-27-2002 05:45 AM
Re: `if' is not matched - message in shell script
the good message is: Is was the ftp-transfer!
the bad one ist that i didnt think about this first.
I never had problems with this before and the "tranfer mode auto" button in my ftp client always worked well - until yesterday
Thanks for opening my eyes ;-) This has saved my weekend - enjoy yours!
Is there a way to detect such problems in a file, cat and more showed the correct code?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-27-2002 05:50 AM
тАО09-27-2002 05:50 AM
Re: `if' is not matched - message in shell script
strings chartest1 >chartest2
Does any conditional work? How about a numeric test?
export TEST=1
if (( $TEST == 1 ))
then
print "test is one"
else
print "test not one"
fi
I would be tempted to look at environment variables and the shell you are using. Can you tell us which shell you are logged in as, and what the output of the 'env' statement is?
Share and Enjoy! Ian
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-27-2002 05:52 AM
тАО09-27-2002 05:52 AM
Re: `if' is not matched - message in shell script
Use the view command (readonly vi) - that will show you the ^M character.
Rgds, Robin.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-27-2002 05:54 AM
тАО09-27-2002 05:54 AM
Re: `if' is not matched - message in shell script
-- Rod Hills
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-27-2002 05:58 AM
тАО09-27-2002 05:58 AM
Re: `if' is not matched - message in shell script
Sounds like you are editing your scripts / files on a PC then transferring them to UNIX. This is common for new UNIX users. If so, I suggest you bite the bullet and learn vi. It's not the world's most user-friendly text editor, especially if you're used to a word processor on your PC, however it's available on every "UNIX like" system whether you use a GUI or not.
Darrell
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-27-2002 06:02 AM
тАО09-27-2002 06:02 AM
Re: `if' is not matched - message in shell script
Yet another way to view control characters in a file is with 'cat -vt'. A carriage return shows as ^M and a tab character appears as ^I.
A useful reference is 'man ascii(5)'.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-27-2002 06:13 AM
тАО09-27-2002 06:13 AM
Re: `if' is not matched - message in shell script
Indeed I edited the files on an PC and transferred them to the HP - this worked fine for all the etc/*s and other config files I had to edit during the last weeks.
I even started with vi and use it every time when i am at the HP-box, but it runs a EEG-recording software 24/7 and is occupied by a technician most time, so I hav to use telnet. And vi causes problems with my telnet client (CRT for Win) - so I used a Win-Editor with built-in ftp-client.
Well at least I am now aware of the problem - strange that it didnt appear earlier ;-)
Thanks to all of you and enjoy your weekend
Christia
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-27-2002 06:17 AM
тАО09-27-2002 06:17 AM
Re: `if' is not matched - message in shell script
my 2 cents
-- Rod Hills
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-27-2002 06:22 AM
тАО09-27-2002 06:22 AM
Re: `if' is not matched - message in shell script
I noticed you're pretty new to the forums. May I point out the following link ?
http://forums.itrc.hp.com/cm/QuestionAnswer/1,,0x022718276953d61190040090279cd0f9,00.html
This explains (amongst other things) about the points system.
Tom