fish - Syntax error in script -


my script try execute mvn clean install in projects before tried switch dev branch , pull it.

successstring="[info] build success"; file="mvnoutput"; red=$'\e[1;31m'; grn=$'\e[1;32m'; end=$'\e[0m';  function checkresult     if grep -fxq "$successstring" $file              echo -en "${grn}[${1}]build ok${end}";     else             echo "${red}[${1}]error in mvn clean install${end}";         exit 1;     fi; end  function pullandswitchdevbranch     git checkout dev;     git pull origin dev; end   cd api-pay-commons/; pullandswitchdevbranch; touch mvnoutput; mvn clean install -u > mvnoutput; checkresult pay; 

why received error?

line 17: end: command not found ./script.sh: line 20: syntax

error near unexpected token git' ./script.sh: line 20: git checkout dev;'

you have used "fish" tag, i'm assuming running fish shell.

if so: not valid fish script. fish explicitly not posix-compatible, might want read on syntax. (if not, please correct tag)

red=$'\e[1;31m';

fish not use var=value set variable. uses set var value.

fish not have $'' style of quoting. instead, backslash-escapes interpreted outside of quotes.

so set red \e"[1;31m". alternatively, fish offers set_color builtin, prints escape sequence given color. set red (set_color red) (or call set_color later).

then 

fish not use if condition; dosomething; fi. it's if condition; dosomething; end.

echo -en "${grn}[${1}]build ok${end}"; 

fish not use "${var}". not call function arguments $1 et al.

this echo -ens "$grn" "[$argv[1]]" "build ok" "$end".

exit 1 

fish not allow exiting functions. you'll have return 1 , check result outside.

additionally, you're using semicolons on place, not typical style in shell i'm aware of.


in case not using fish, posix-compatible shell (like bash), not valid. main (and possibly only) issue using function something; dosomething; end. in bash, be

 function () {       #dostuff  } 

and in pure posix,

 () {      #dostuff  } 

Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -