0

Why does this script give me a syntax error running ubuntu 18.04?

#!/bin/sh

# Copyright (c) 2011 Altera Corporation. All rights reserved.

# Your use of Altera Corporation's design tools, logic functions and other
# software and tools, and its AMPP partner logic functions, and any output files
# any of the foregoing (including device programming or simulation files), and
# any associated documentation or information are expressly subject to the terms
# and conditions of the Altera Program License Subscription Agreement, Altera
# MegaCore Function License Agreement, or other applicable license agreement,
# including, without limitation, that your use is for the sole purpose of
# programming logic devices manufactured by Altera and sold by Altera or its
# authorized distributors.  Please refer to the applicable agreement for
# further details.

script_path=`dirname $0`

if [ -z $script_path ] ;then
    script_path=`which $0 |& tail -1`
fi

if [ $script_path = "." -o $script_path = "" ] ;then
    script_path=`pwd`
fi

if [ ${script_path:0:1} != "/" ] ; then
    script_path=`pwd`/$script_path
fi

export ROOTDIR=$script_path
export CMD_NAME=`basename $0`

if test $CMD_NAME = "setup" ; then
    export CMD_NAME="altera_installer_cmd --source=$ROOTDIR"

    LOG="$(mktemp /tmp/altera_setup.log.XXXXXXXXXX)"

    # no args; default to GUI install based on root directory type
    if [ -z $1 ]; then
        _setup_args="--dvd"
        if [ -f $ROOTDIR/.setup_args ]; then :
            _setup_args=`cat $ROOTDIR/.setup_args`
        fi

        export CMD_NAME="$CMD_NAME $_setup_args"

        echo "Welcome to Altera Software Installer"
        echo "Copyright (c) Altera Corporation 2011"
        echo ""
        echo "Starting GUI. If nothing shows up, or you don't have an X display, run:"
        echo "   ./setup --help "
        echo "for commandline usage."
        echo "NOTE: All output has been redirected to $LOG"
        echo ""
    fi

    export LD_LIBRARY_PATH=$ROOTDIR/altera_installer/bin:$LD_LIBRARY_PATH
    export PATH=$ROOTDIR/altera_installer/bin:$PATH

    if [ -z $1 ]; then
        eval exec "$CMD_NAME $@ &> $LOG"
    else
        eval exec "$CMD_NAME $@"
    fi
elif test $CMD_NAME = "autorun.sh" ; then
    export CMD_NAME="autorun"
    export LD_LIBRARY_PATH=$ROOTDIR/autorun:$LD_LIBRARY_PATH
    export PATH=$ROOTDIR/autorun:$PATH

    LOG="$(mktemp /tmp/altera_dvd_autorun.log.XXXXXXXXXX)"

    eval exec "$CMD_NAME $@ &> $LOG"
fi

I'm getting this error: ./setup: 1: ./setup: Syntax error: "&" unexpected

muru
  • 197,895
  • 55
  • 485
  • 740
dos584
  • 101
  • 3
  • 2
    Your script uses /bin/sh, but |&, &> are bash features. – muru Aug 22 '18 at 03:49
  • The files were created using mount. I tried changing the script but the permissions are locked to root and chmod commands are leaving it at read only using sudo chmod 777 setup. I realise this might be off topic to the question but how can i change the permissions so i can edit this?

    I get the message: chmod: changing permissions of 'setup': Read-only file system

    – dos584 Aug 22 '18 at 04:26
  • if you can, try running the script with bash ./setup – muru Aug 22 '18 at 05:04
  • 3
    So, apparently this is a script written by Altera. The company mostly supports RHEL and CentOS, and on those /bin/sh is symlink to /bin/bash. muru is correct - the script is using bash specific syntax, so you either should change the #! line or use bash scriptname.sh way – Sergiy Kolodyazhnyy Aug 22 '18 at 06:16
  • @SergiyKolodyazhnyy Thanks for the reply, this seems like the right thing to do but i've run into another problem. The terminal spits out:

    `Welcome to Altera Software Installer Copyright (c) Altera Corporation 2011

    Starting GUI. If nothing shows up, or you don't have an X display, run: ./setup --help for commandline usage. NOTE: All output has been redirected to /tmp/altera_setup.log.ZayF0vZOZi`

    Nothing shows up after this is shown, do i need an "X display"?

    – dos584 Aug 23 '18 at 06:22
  • @dos584 X display is basically GUI desktop, as contrasted with using just a plain terminal. Try looking at the log file it created, it may give a hint as to what went wrong (the /tmp/altera_setup.log.ZayF0vZOZi one). If you already rebooted, /tmp will be cleared, so if you don't find that file after reboot, just run the script again, and see what new log file it created – Sergiy Kolodyazhnyy Aug 23 '18 at 06:40
  • @SergiyKolodyazhnyy setup: line 61: /cdrom/cdrom0/altera_installer/bin/altera_installer_cmd: No such file or directory . This file and directory definitely exists but the file is locked by root in read only. Doing sudo bash ./setup returns the same result. Attempts to make it read and write with chmod fail exactly the same as my attempt above with the setup file. – dos584 Aug 23 '18 at 07:17

0 Answers0