Unix/Linux Go Back    


Shell Programming and Scripting BSD, Linux, and UNIX shell scripting — Post awk, bash, csh, ksh, perl, php, python, sed, sh, shell scripts, and other shell scripting languages questions here.

Error in script

Shell Programming and Scripting


Reply    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 3 Weeks Ago   -   Original Discussion by Avinash Sinha
Avinash Sinha's Unix or Linux Image
Avinash Sinha Avinash Sinha is offline
Registered User
 
Join Date: Nov 2017
Last Activity: 20 November 2017, 5:20 AM EST
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Unix or Linux Question Error in script

While installing kubernetes, I have to run 1 script. Below is a part of that code. I am getting an error as

Code:
-bash: syntax error near unexpected token `}'

Please help me to find what changes are required for the below mentioned piece of code.



Code:
kube::util::godep_restored() {
  local -r godeps_json=${1:-Godeps/Godeps.json}
  local -r gopath=${2:-${GOPATH%:*}}
  if ! which jq &>/dev/null; then
    echo "jq not found. Please install." 1>&2
    return 1
  fi
  local root
  local old_rev=""
  while read path rev 
do
    rev=$(echo "${rev}" | sed "s/['\"]//g") # remove quotes which are around revs sometimes

    if [[ "${rev}" == "${old_rev}" ]] && [[ "${path}" == "${root}"* ]]; then
      # avoid checking the same git/hg root again
      continue
    fi

    root="${path}"
    while [ "${root}" != "." -a ! -d "${gopath}/src/${root}/.git" -a ! -d "${gopath}/src/${root}/.hg" ] 
	do
      root=$(dirname "${root}")
    done
    if [ "${root}" == "." ]; then
      echo "No checkout of ${path} found in GOPATH \"${gopath}\"." 1>&2
      return 1
    fi
    local head
    if [ -d "${gopath}/src/${root}/.git" ]; then
      head="$(cd "${gopath}/src/${root}" && git rev-parse HEAD)"
    else
      head="$(cd "${gopath}/src/${root}" && hg parent --template '{node}')"
    fi
    if [ "${head}" != "${rev}" ]; then
      echo "Unexpected HEAD '${head}' at ${gopath}/src/${root}, expected '${rev}'." 1>&2
      return 1
    fi
    old_rev="${rev}"
  done<(jq '.Deps|.[]|.ImportPath + " " + .Rev' -r < "${godeps_json}")
  return 0
}


Last edited by Scrutinizer; 3 Weeks Ago at 01:39 AM.. Reason: code tags
Sponsored Links
    #2  
Old Unix and Linux 3 Weeks Ago   -   Original Discussion by Avinash Sinha
Scrutinizer's Unix or Linux Image
Scrutinizer Scrutinizer is online now Forum Staff  
Moderator
 
Join Date: Nov 2008
Last Activity: 13 December 2017, 1:41 PM EST
Location: Amsterdam
Posts: 11,649
Thanks: 518
Thanked 3,385 Times in 2,984 Posts
On the two but last line:

Code:
done<( ....

try:

Code:
done < <( ...


Last edited by Scrutinizer; 3 Weeks Ago at 03:46 AM..
Sponsored Links
    #3  
Old Unix and Linux 3 Weeks Ago   -   Original Discussion by Avinash Sinha
Avinash Sinha's Unix or Linux Image
Avinash Sinha Avinash Sinha is offline
Registered User
 
Join Date: Nov 2017
Last Activity: 20 November 2017, 5:20 AM EST
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
I tried with the suggested option, but it's still not working. I am getting below error :

Code:
syntax error near unexpected token `<'

Code snippet :

Code:
{
  local -r godeps_json=${1:-Godeps/Godeps.json}
  local -r gopath=${2:-${GOPATH%:*}}
  if ! which jq &>/dev/null; then
    echo "jq not found. Please install." 1>&2
    return 1
  fi
  local root
  local old_rev=""
  while read path rev 
do
    rev=$(echo "${rev}" | sed "s/['\"]//g") # remove quotes which are around revs sometimes

    if [[ "${rev}" == "${old_rev}" ]] && [[ "${path}" == "${root}"* ]]; then
      # avoid checking the same git/hg root again
      continue
    fi

    root="${path}"
    while [ "${root}" != "." -a ! -d "${gopath}/src/${root}/.git" -a ! -d "${gopath}/src/${root}/.hg" ] 
do
      root=$(dirname "${root}")
    done
    if [ "${root}" == "." ]; then
      echo "No checkout of ${path} found in GOPATH \"${gopath}\"." 1>&2
      return 1
    fi
    local head
    if [ -d "${gopath}/src/${root}/.git" ]; then
      head="$(cd "${gopath}/src/${root}" && git rev-parse HEAD)"
    else
      head="$(cd "${gopath}/src/${root}" && hg parent --template '{node}')"
    fi
    if [ "${head}" != "${rev}" ]; then
      echo "Unexpected HEAD '${head}' at ${gopath}/src/${root}, expected '${rev}'." 1>&2
      return 1
    fi
    old_rev="${rev}"
  done < <(jq '.Deps|.[]|.ImportPath + " " + .Rev' -r < "${godeps_json}")
  return 0
}

Moderator's Comments:
Error in script Please use CODE tags as required by forum rules!

Last edited by RudiC; 3 Weeks Ago at 09:44 AM.. Reason: Added CODE tags.
    #4  
Old Unix and Linux 3 Weeks Ago   -   Original Discussion by Avinash Sinha
RudiC's Unix or Linux Image
RudiC RudiC is online now Forum Staff  
Moderator
 
Join Date: Jul 2012
Last Activity: 13 December 2017, 1:42 PM EST
Location: Aachen, Germany
Posts: 11,794
Thanks: 339
Thanked 3,659 Times in 3,357 Posts
What's your shell version? "process substitution" works only in recent shells.
Sponsored Links
    #5  
Old Unix and Linux 3 Weeks Ago   -   Original Discussion by Avinash Sinha
Avinash Sinha's Unix or Linux Image
Avinash Sinha Avinash Sinha is offline
Registered User
 
Join Date: Nov 2017
Last Activity: 20 November 2017, 5:20 AM EST
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts

Code:
$ echo $BASH_VERSION
4.4.12(3)-release

I am running this script through CYGWIN as I could not find any other option to run shell script in windows machine. Please let me know if I need to download the latest version or any other tool to run this script.

Last edited by Scott; 3 Weeks Ago at 04:15 AM.. Reason: Code tags
Sponsored Links
    #6  
Old Unix and Linux 3 Weeks Ago   -   Original Discussion by Avinash Sinha
RudiC's Unix or Linux Image
RudiC RudiC is online now Forum Staff  
Moderator
 
Join Date: Jul 2012
Last Activity: 13 December 2017, 1:42 PM EST
Location: Aachen, Germany
Posts: 11,794
Thanks: 339
Thanked 3,659 Times in 3,357 Posts
What does your bash's man page say about "process substitution"?
Sponsored Links
    #7  
Old Unix and Linux 3 Weeks Ago   -   Original Discussion by Avinash Sinha
Avinash Sinha's Unix or Linux Image
Avinash Sinha Avinash Sinha is offline
Registered User
 
Join Date: Nov 2017
Last Activity: 20 November 2017, 5:20 AM EST
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Can you please help me with the command and what to look for exactly?
Sponsored Links
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Re: Script Error [syntax error at line] anudeepkumar123 UNIX for Dummies Questions & Answers 3 08-15-2011 04:54 PM
Syntax error calling TCL script from shell script marcoss90 Shell Programming and Scripting 1 03-13-2011 10:14 AM
How to grep sql error in shell script and exit the script? allinshell99 Shell Programming and Scripting 2 05-27-2010 10:06 PM
Error opening script file - location error starcraftbud Windows & DOS: Issues & Discussions 9 02-17-2010 05:56 PM
awk Shell Script error : "Syntax Error : `Split' unexpected Herry UNIX for Dummies Questions & Answers 2 03-17-2008 12:16 PM



All times are GMT -4. The time now is 02:49 PM.