Bash Syntax Error Redirection Unexpected
Contents |
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 /bin/sh 1 syntax error redirection unexpected more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users bash syntax error unexpected token Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping bash syntax error unexpected end of file each other. Join them; it only takes a minute: Sign up Bash: Syntax error: redirection unexpected up vote 53 down vote favorite 11 I do this in a script: read direc <<< $(basename `pwd`) and I get: Syntax bash syntax error near unexpected token error: redirection unexpected in an ubuntu machine /bin/bash --version GNU bash, version 4.0.33(1)-release (x86_64-pc-linux-gnu) while I do not get this error in another suse machine: /bin/bash --version GNU bash, version 3.2.39(1)-release (x86_64-suse-linux-gnu) Copyright (C) 2007 Free Software Foundation, Inc. Why the error? bash share|improve this question edited Mar 6 at 17:20 Willi Mentzel 2,33291840 asked Mar 17 '10 at 12:58 flow 4,2643295157 For reference, the command works on cygwin as well ( /bin/bash --version
Bash Syntax Error Near Unexpected Token Done'
GNU bash, version 3.2.49(23)-release (i686-pc-cygwin) Copyright (C) 2007 Free Software Foundation, Inc. ) –hlovdal Mar 17 '10 at 13:08 add a comment| 3 Answers 3 active oldest votes up vote 92 down vote accepted Does your script reference /bin/bash or /bin/sh in its hash bang line? The default system shell in Ubuntu is dash, not bash, so if you have #!/bin/sh then your script will be using a different shell than you expect. Dash does not have the <<< redirection operator. share|improve this answer answered Mar 17 '10 at 13:05 John Kugelman 173k36306384 Is there a way to fix this easily ? –Sliq Dec 21 '14 at 20:52 3 @Sliq, yes use !#/bin/bash. –ahmet alp balkan Jan 4 '15 at 21:03 2 seems this is happenning to me in a shell script with a <<< operator thas works on my local machine but not on the server; but using !#/bin/bash does not solve the problem. Local is "3.2.0-74-generic #109-Ubuntu", server is "3.5.0-54-generic #81~precise1-Ubuntu" –Packet Tracer Jan 28 '15 at 14:56 2 my error was that i was invoking the script with sh script_name.sh, so was not using bash though it was specified in the script as !#/bin/bash –Packet Tracer Jan 28 '15 at 15:03 add a comment| up vote 1 down vote do it the simpler way, direc=$(basename `pwd`) Or use the she
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
Bash Syntax Error Near Unexpected Token Echo'
developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask bash syntax error near unexpected token (' ubuntu 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 bash syntax error near unexpected token else' them; it only takes a minute: Sign up shell script syntax error: redirection unexpected during done command up vote 0 down vote favorite So, I'm trying to make a shell script for a class and it basically just performs http://stackoverflow.com/questions/2462317/bash-syntax-error-redirection-unexpected a few administrative operations. Right now, I'm getting a syntax error on the done command on lines 27 and 45. I feel it might be my use of awk. #!/bin/sh ps -cefl > userInfo while [ "$menuOption" != 4 ]; do echo "====================================" echo "Select a menu option!" echo "(1) Ancestry History" echo "(2) Who's online" echo "(3) What process a user is running" echo "(4) Exit" echo -n "Menu option:" read menuOption echo " " if [ "$menuOption" http://stackoverflow.com/questions/18777815/shell-script-syntax-error-redirection-unexpected-during-done-command -eq 1 ]; then echo "The ancestry tree for the current process is. . ." echo " " PID=$$ while [ $PID -ne 1 ] do echo $PID echo " | " while read PIDS; do myPID=$(echo $PIDS | awk '{print $1}') myPPID=$(echo $PIDS | awk '{print $2}') if [ $myPID -eq $PID ]; then PID=$myPPID fi done < <(grep $PID userInfo | awk '{printf "%i %i\n",$4,$5}') done echo " 1 " echo " " elif [ "$menuOption" -eq 2 ]; then echo "Online users:" echo "-------------" who | awk '{print $1}' | sort -u echo "-------" echo " " elif [ "$menuOption" -eq 3 ]; then i=0 echo "Select a user to see the processes!" echo "-----------------------------------" while read value; do listNames["$i"]="$value" echo "$i)${listNames[$i]}" i=$(($i+1)) done < <(who | awk '{print $1}' | sort -u) echo -n "Select user: " read userOption echo " " echo "You've selected: ${listNames[$userOption]}" grep ${listNames[$userOption]} userInfo | awk '{printf "%-7s %-7s %-7s %-7s %-7s %-7s %-10s %s %s\n",$3,$4,$5,$9,$11,$12,$13,$14,$15}' | sort; echo " " elif [ "$menuOption" -eq 4 ]; then echo "Exiting Script!" fi done bash shell ubuntu awk share|improve this question asked Sep 13 '13 at 3:27 T.J. Williams 114 You might want to read about the select command in bash. –chepner Sep 13 '13 at 13:12 add a comment| 2 Answers 2 active oldest votes up vote 6 down vote No, it's due
Search HCL Search Reviews Search ISOs Go to Page... LinuxQuestions.org > Forums > Linux Forums > Linux - General bash script: Syntax error: redirection unexpected http://www.linuxquestions.org/questions/linux-general-1/bash-script-syntax-error-redirection-unexpected-927865/ User Name Remember Me? Password Linux - General This Linux forum is for general Linux questions and discussion. If it is Linux Related and doesn't seem to fit in any other forum http://unix.stackexchange.com/questions/45781/shell-script-fails-syntax-error-unexpected then this is the place. Notices Welcome to LinuxQuestions.org, a friendly and active Linux Community. You are currently viewing LQ as a guest. By joining our community you will have the syntax error ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today! Note that registered members see fewer ads, and ContentLink is completely disabled once you log in. Are you new to LinuxQuestions.org? Visit the following links: Site Howto | Site FAQ | bash syntax error Sitemap | Register Now If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here. Having a problem logging in? Please visit this page to clear all LQ-related cookies. Introduction to Linux - A Hands on Guide This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter. For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author's experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own. Click Here to receive this Complete Guide absolutely free. Search this Thread 02-06-2012, 04:50 AM #1 make Member Registered: Apr 2004 Distribution: Mandriva, Ubuntu, openS
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 Unix & Linux Questions Tags Users Badges Unanswered Ask Question _ Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. 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 Shell script fails: Syntax error: “(” unexpected up vote 31 down vote favorite 7 I've been working on a script that automates setting up a development environment for Raspberry Pi development (step by step details that work are here). The script is linked in that article but convenience you can find it here also. Now when run this script install and sets up the environment without error but you have to enter your sudo password more than once due to sudo's time-out value by default. So I started experimenting by removing all the sudo lines and running the whole script via sudo at the command line like so: kemra102@ubuntuvm:~$ sudo ./pi_dev_env_install.sh This works fine as expected and gets most of the way through until this point: ./pi_dev_env_install: 68: ./pi_dev_env_install.sh: Syntax error: "(" unexpected Now this line worked fine previously when not running the whole script with sudo. There is nothing about this line running as sudo that should stop it working to my knowledge, does anyone have any ideas? bash shell ubuntu shell-script share|improve this question edited Aug 18 '12 at 12:08 Gilles 369k666681119 asked Aug 18 '12 at 11:37 kemra102 4681613 The shebang is really in line 9? Due to Ubuntu's DashAsBinSh affinity I suspect your script is interpreted by dash instead of bash. Try to move the shebang in line 1. –manatwork Aug 18 '12 at 11:45 According to that article calling /bin/bash directly instead of /bin/sh will; correctly use bash instead of dash so that should not be an issue as I understand it. I can still move the shebang of course, but that doesn't really explain as to why it works when you don’t sudo the whole script. –kemra102 Aug 18 '12 at 11:50 add a comment| 5 Answers 5 active oldest votes up vote 47 down vote accepted The script does not begin with a shebang line, so the kernel executes it with /bin/sh. On Ubuntu, /bin/sh is da