Argument Expected Error Unix Shell Script
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and unix shell script argument passing policies of this site About Us Learn more about Stack Overflow the company unix shell script input arguments Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users unmatched error in unix shell script Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a
$0 In Unix Shell Script
minute: Sign up getting Error ksh[7]: test: argument expected up vote 0 down vote favorite When executing the below line , am getting the error ksh[7]: test: argument expected while [ $cont = "y" ] Whats wrong with this line? shell share|improve this question edited Jul 2 '13 at 13:33 Holger Just 26k65680 asked Jul 2 '13 at 13:29 user2519862 add unix shell script parameter a comment| 1 Answer 1 active oldest votes up vote 1 down vote accepted $cont might not be set, which is why it fails. Enclose the variable in double quotes like this: while [ "$cont" = "y" ] share|improve this answer answered Jul 2 '13 at 13:34 dogbane 136k42235322 I have set it as cont="y".. So what shuld be wrong then? –user2519862 Jul 2 '13 at 13:35 Its working fine now, after adding the double quotes as u suggested.Thanks a lot!!! –user2519862 Jul 2 '13 at 13:37 add a comment| Your Answer draft saved draft discarded Sign up or log in Sign up using Google Sign up using Facebook Sign up using Email and Password Post as a guest Name Email Post as a guest Name Email discard By posting your answer, you agree to the privacy policy and terms of service. asked 3 years ago viewed 5760 times active 3 years ago Related 774How to mkdir only if a dir does not already exist?577How to set a variable equal to the output from a command in Bash?4
Help Receive Real-Time Help Create a Freelance Project Hire for a Full Time Job Ways to Get Help Ask a Question Ask for Help Receive Real-Time Help Create a Freelance Project Hire for a Full Time Job Ways to unix shell script variable Get Help Expand Search Submit Close Search Login Join Today Products BackProducts Gigs
Unix Shell Script Parameter With Spaces
Live Careers Vendor Services Groups Website Testing Store Headlines Experts Exchange > Questions > [: argument expected message while executing Unix
Linux Shell Script Parameter
Shell Script. Want to Advertise Here? Solved [: argument expected message while executing Unix Shell Script. Posted on 2014-05-04 Unix OS 1 Verified Solution 5 Comments 1,071 Views Last Modified: 2014-05-04 Hi, I have http://stackoverflow.com/questions/17426944/getting-error-ksh7-test-argument-expected script temp.sh in that I have variable MONTH MONTH receives values dynamically on some other conditions. For Example MONTH can have values like this MONTH=BD0 or MONTH=BD4 or MONTH=' ' i.e null values Script has a condition it should not be BD0 or Null values then only execute. This conditions executes When MONTH has values. if [ $MONTH != "BD0" ] && [ ! -z "$$MONTH" -a "$$MONTH" != https://www.experts-exchange.com/questions/28425876/argument-expected-message-while-executing-Unix-Shell-Script.html " " ] But when MONTH does not have any values i.e null/blank value it gives this message but continues to else caluse. temp.sh[94]: [: argument expected How to avoid this message repeating when ever there is null values in the MONTH. Thanks & Regards, Sailaja 0 Question by:welcome 123 Facebook Twitter LinkedIn Google LVL 68 Active today Best Solution bywoolmilkporc Did you try the double quotes around "$MONTH" ? if [ "$MONTH" != "BD0" ] && [ ! -z "$MONTH" -a "$MONTH" != " " ] If your shell is bash or ksh use double square brackets. No quoting necessary, Go to Solution 4 Comments LVL 68 Overall: Level 68 Unix OS 53 Message Active today Expert Comment by:woolmilkporc2014-05-04 The easiest way is enclosing "$MONTH" in double quotes. But you could also set a default value, so that MONTH cannot be empty. So before MONTH receives values dynamically add something like MONTH="dummy" or whatever content you find useful. By the way, do the double "$$" signs make any sense? Or is it just typos? 0 Message Author Comment by:welcome 1232014-05-04 Sorry it is typos while typing, it single $ only not $$. I can't have any value by default, because if null/bl
Database CPUs Solaris Novell OpenVMS DOS Unix Mac Lounge Login» Register» Connect» Hardware & Devices ▼ General Hardware http://www.computing.net/answers/programming/error-test-argument-expected/18951.html CPUs/Overclocking Networking See More... Software ▼ Security and Virus Office Software PC Gaming See More... Operating Systems ▼ Windows 10 Windows 8 Windows 7 Windows XP See More... Off-Topic Tags How-tos Drivers http://askubuntu.com/questions/536409/ubuntu-bash-if-lessthan-else-condition-returning-error-lt-argument-expected Ask a Question Computing.NetForumsProgrammingTheory Error : test: argument expected Tags:testerrorscriptDirectory Bhargav Teja May 7, 2009 at 01:02:16 Specs: Unix Hi,When i execute the following script i'm getting test: argument expected error shell script at if [ -z $file ]. Can someone plz advise.if [ -z $file ]thenecho " DID NOT ENTER A FILE NAME "elif [ ! -f $file ]thenecho " \t File ' $file ' Doesn't Exists In $PWD Directory \n"elseecho " \t File ' $file ' Exists In $PWD Direcotry \n"fiThanks. See More: Error : test: argument expected Report • #1 nails May 7, unix shell script 2009 at 07:02:57 Your script worked for me with no problems: #!/bin/ksh read file if [ -z "$file" ] then echo " DID NOT ENTER A FILE NAME " elif [ ! -f "$file" ] then echo " \t File ' $file ' Doesn't Exists In $PWD Directory \n" else echo " \t File ' $file ' Exists In $PWD Direcotry \n" fi BTW, it's always a good idea to include the shell invocation on line 1 of your script. I'd surround $file with double quotes "$file" Have you tried the extended test facility - two brackets instead of 1: #!/bin/ksh read file if [[ -z $file ]] then echo " DID NOT ENTER A FILE NAME " elif [[ ! -f $file ]] then echo " \t File ' $file ' Doesn't Exists In $PWD Directory \n" else echo " \t File ' $file ' Exists In $PWD Direcotry \n" fi Report • Start a discussion Related Solutions› [Solved] Batch Script typeperf.exe MONITOR CPU PROCESS › [Solved] How to BATCH ANTIVIRUS and CLEANING SCRIPT AUTOMATION › [Solved] How can I turn off output to myfilename.log › [Solve
communities company blog Stack Exchange Inbox Reputation and Badges sign up log in tour help Tour Start here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Ask Ubuntu Questions Tags Users Badges Unanswered Ask Question _ Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute: Sign up Here's how it works: Anybody can ask a question Anybody can answer The best answers are voted up and rise to the top Ubuntu bash if lessthan else condition returning error [: -lt: argument expected up vote 0 down vote favorite I am doing the following script to know if profit or loss from entered selling price and cost price as; echo enter selling price read sprice echo enter costprice read cprice if [ $sprice -lt $cp ] then echo Loss else echo Profit fi All the time, it is returning Profit , with an error code, like; :~/shell$ sh shellb.sh enter selling price 10 enter costprice 20 shellb.sh: 6: [: -lt: argument expected Profit what might be the reason, and how can I fix this? command-line bash scripts share|improve this question asked Oct 13 '14 at 5:29 blasteralfred Ψ 1032 Feel free to take a look at: shellcheck.net –Cyrus Oct 13 '14 at 5:37 Sure and thanks @Cyrus –blasteralfred Ψ Oct 13 '14 at 6:05 add a comment| 1 Answer 1 active oldest votes up vote 0 down vote accepted Change the $cp variable to $cprice which is what you read in the line that says read cprice. echo enter selling price read sprice echo enter costprice read cprice if [ $sprice -lt $cprice ] then echo Loss else echo Profit fi The script returns Profit even if $sprice has the same value as $cprice, so to be accurate add these lines to your script: elif [ $sprice -eq $cprice ] then echo Break\ even So what you end up with is: echo enter selling price read sprice echo enter costprice read cprice if [ $sprice -lt $cprice ] then echo Loss elif [ $sprice -eq $cprice ] then echo Break\ even else echo Profit fi share|improve this an