LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
Search this Thread
Old 05-29-2011, 02:54 PM   #1
emcykm
LQ Newbie
 
Registered: Mar 2011
Posts: 10

Rep: Reputation: 0
Shell Script is showing error after whenever checking a special variable


Dear All,

I have created a shell script to customise mv command, now i have achieved to accomplish all the functionality of mv by using alias. But i found difficulty in accomplish the funcionality with options [Like mv -i or mv -f etc.]. I thought about logic which check the first argument whether its starting with a minus [-] or not. if its starting with argument it will set a flag and execute accordingly. But whenever this condition is checked it shell script will throw error of destination operand missing. But the same will work with out option.

Note: I have used an minus[-] expression for decreasing a counter on the script above.

Kindly help me to get rid of this issue...

The below mentioned is the portion of script. Sry for troubling Im not gud @scripting.

for i in $*
do
{
argument=`expr $argument - 1`
if [ $argument = 0 ];
then
exit
fi
x=`echo "$i" | cut -c 1`
if [ "$x" = '-' ];
then
{
opz=$i
a_flag=1
}
fi

With Regards,
Emcy
 
Old 05-29-2011, 02:59 PM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,384

Rep: Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963
Do you not just want look at using getopts to properly parse options?
 
Old 05-29-2011, 03:09 PM   #3
emcykm
LQ Newbie
 
Registered: Mar 2011
Posts: 10

Original Poster
Rep: Reputation: 0
Smile Getopts

Dear acid_kewpie,

Thanks for prompt reply...
I have already thought about that, bt that will cost me for entire restructuring of my scripts. I thought that it can be used if this logic is not at all possible...
hope we can resolve the mentioned error and can use same logic.

with Regards,
Emcy
 
Old 05-29-2011, 06:54 PM   #4
grail
Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 7,485

Rep: Reputation: 1890Reputation: 1890Reputation: 1890Reputation: 1890Reputation: 1890Reputation: 1890Reputation: 1890Reputation: 1890Reputation: 1890Reputation: 1890Reputation: 1890
May help if you advise what the value of 'argument' is originally set to? (seeing it is not in this part of the script)

We may require more information to seeing that the code you have provided is so simple that I am not sure I can see what
would be erroring specifically.
 
Old 05-29-2011, 10:53 PM   #5
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.5, Centos 5.10
Posts: 16,261

Rep: Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028
1. Try creating a minimal code file that exhibits the same error

2. add
Code:
set -xv
as the 2nd line of code after the bash invocation

3. The syntax for a do loop is
Code:
for blah
do    <some lines of code>
done
Parentheses '{}' are for defining fns.
Ditto for if ... then .. fi blocks; no parens needed.

4. in your example you have 2 '{' and only 1 '}'

5. You may find these useful
http://rute.2038bug.com/index.html.gz
http://tldp.org/LDP/Bash-Beginners-G...tml/index.html
http://www.tldp.org/LDP/abs/html/
 
Old 06-01-2011, 09:59 AM   #6
emcykm
LQ Newbie
 
Registered: Mar 2011
Posts: 10

Original Poster
Rep: Reputation: 0
Smile Thnks to All!!!!!!

Dear All,

Thanks to all!!!

The issue has been solved after defining passing 3 arguments, one for option, one for destination and one for source file....
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
nice little shell script needs some "error checking" help pendal Programming 2 10-18-2009 11:06 AM
pass variable from one shell script into another shell script xskycamefalling Programming 9 10-03-2009 01:45 AM
cluster job checking and c-shell script bostonuser Programming 4 06-08-2009 04:37 PM
expanding variable in shell script dipenchaudhary Programming 8 02-08-2006 05:05 PM
Proccess checking within shell script khutze Programming 2 08-12-2002 01:07 PM


All times are GMT -5. The time now is 10:20 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration