- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Urgent Help in Scripting
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
Forums
Discussions
Discussions
Discussions
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
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
04-02-2007 06:45 PM
04-02-2007 06:45 PM
Urgent Help in Scripting
#!/usr/bin/bash
cp /home/admin/atul/OBC/nit1 /home/admin/atul/KBC/nit1
$var = `echo "$?"` ####### Checking the status of previous command
if [$val = 0 ]; then
rm /home/admin/atul/OBC/nit1
else
echo "Copy Failed";
fi
+++++++++++++++++++++++++++++++++++++++++
but while executing script i am getting this error:
ssmove.sh: line 3: =: command not found
ssmove.sh: line 4: [: -eq: unary operator expected
Copy Failed
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-02-2007 07:03 PM
04-02-2007 07:03 PM
Re: Urgent Help in Scripting
If u want to copy and delete after success why
don't u use mv command.
$ mv /home/admin/atul/OBC/nit1 /home/admin/atul/KBC/nit1
Also while setting variables don't use $ sign.
and don't use spaces on either side of =.
--$var = `echo "$?"` ####### Checking the status of previous command
Use
var=`echo "$?"` ####### Checking the status of previous command.
And no need to store $? in var, u can directly compare $? like following
if [ $? -eq 0 ]; then
Also
--if [$val = 0 ]; then
since $? returns a number, to compare a number u have to use -eq instead of =,
because = compares strings.
-Santosh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-02-2007 07:06 PM
04-02-2007 07:06 PM
Re: Urgent Help in Scripting
I think you need just a
"[" and "$val".
another way:
# cp A B && rm A || echo ERROR.
rgds
HGH
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-02-2007 07:06 PM
04-02-2007 07:06 PM
Re: Urgent Help in Scripting
not a fan of bash, so this is my guess:
1. line 3
val = `echo "$?"`
2. line 4
if [ $val -eq 0 ]
Although I think line 3 should be val = $?
Please also read:
http://forums1.itrc.hp.com/service/forums/helptips.do?#33 on how to reward any useful answers given to your questions.
So far you have only awarded points to 1 of 33 answers !
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-02-2007 07:22 PM
04-02-2007 07:22 PM
Re: Urgent Help in Scripting
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-02-2007 07:31 PM
04-02-2007 07:31 PM
Re: Urgent Help in Scripting
= `echo "0"`
which looks like you're trying to run a command named "=". That's why the error message is "command not found".
Line 4: you're using an uninitialized variable, for two reasons.
1) the previous command did not succeed
2) you have a typo: in the line 3, you store to "var", here you request the value of "val".
If a variable might have an empty value, you should always put double quotes around it.
After variable expansion, this command line expands to:
if [ = 0 ]; then
The error message comes from the "[" command (also known as "test", usually implemented as shell internal command but available as a separate binary too). For it "-eq" and "=" are synonymous, so it displays "=" as "-eq".
If the expression between the brackets begins with an operator, it must be the kind of operator that takes only one argument, i.e. an unary argument. As the unquoted variable expanded to nothing at all, it broke your expression.
Your script also seems over-complex.
You could do it more simply like this:
#!/bin/sh
if cp /home/admin/atul/OBC/nit1 /home/admin/atul/KBC/nit1
then
rm /home/admin/atul/OBC/nit1
else
echo "Copy Failed"
fi
The "if" command can be used to test whether the return code of any command is 0 or not-0.
The "[" command evaluates the expression given to it and sets its return code according to the truth value of the expression.
Combining these two creates the familiar "if [ ... ]" structure.