Bash Process Substitution Syntax Error
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 bash process substitution syntax error near unexpected token Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation syntax error bad substitution Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like syntax error in substitution sap you, helping each other. Join them; it only takes a minute: Sign up Syntax error in shell script with process substitution up vote 5 down vote favorite 2 I have this shell script which I use to back
Bash Syntax Error Near Unexpected Token Done'
up my system. There is a line: tar -Pzcpf /backups/backup.tar.gz --directory=/ --exclude=proc --exclude=sys --exclude=dev/pts --exclude=backups --exclude=var/log / 2> >(grep -v 'socket ignored' >&2) As you can see, I have been trying to filter out the annoying, useless "socket ignored" error by tar, using this blog post. What I get from shell upon execution is: /bin/sysback: line 45: syntax error near unexpected token >' /bin/sysback: line 45:tar -Pzcpf /backups/backup --directory=/ --exclude=proc --exclude=sys --exclude=dev/pts --exclude=backups --exclude=var/log / bash syntax error near unexpected token else' 2> >(grep -v 'socket ignored' >&2)' linux bash shell process-substitution share|improve this question edited Aug 25 '12 at 13:50 Gilles 55.6k15118178 asked Aug 25 '12 at 8:57 Milad Naseri 2,87911433 I think 2> >( should be 2>(. –Anders Lindahl Aug 25 '12 at 9:01 Didn't give a syntax error after this change, but didn't filter out the output either. –Milad Naseri Aug 25 '12 at 9:03 2 The >(...) process substitution syntax is a non-standard feature, and your shell apparently doesn't support it. Use a different shell, or perhaps a newer version of bash. –Alan Curry Aug 25 '12 at 9:30 I stand corrected, 2> >( seems to be the way to redirect stderr into a subshell, and running (echo "FOO";echo "FOO" >&2) 2> >(grep -v FOO >&2) outputs a single "FOO" with GNU bash 4.2.24. What shell are you using? –Anders Lindahl Aug 25 '12 at 9:32 1 cron will run your scripts using sh, which on a Debian system is dash, not bash. Adding a !#/bin/bash to your script may help (but I'm not as familiar with cron as I should be, and have no direct experience with Debian). –chepner Aug 25 '12 at 13:49 | show 2 more comments 4 Answers 4 active oldest votes up vote 13 down vote accepted The syntax you'v
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 bash syntax error near unexpected token fi' Learn more about hiring developers or posting ads with us Unix & Linux Questions Tags
Bash Syntax Error Invalid Arithmetic Operator
Users Badges Unanswered Ask Question _ Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and
Bash Syntax Error Near Unexpected Token Then'
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 How to http://stackoverflow.com/questions/12120598/syntax-error-in-shell-script-with-process-substitution use process substitution within a case statement without getting syntax errors? up vote 1 down vote favorite I have a script loaded as a service in /etc/init.d/myfile When I try to start the service I get the error /etc/init.d/myservice: 21: /etc/init.d/myservice: Syntax error: "(" unexpected The issue seems to be with the process substitution <( in the source command. I use it without any problem in other scripts to extract variables from my main config file but http://unix.stackexchange.com/questions/178018/how-to-use-process-substitution-within-a-case-statement-without-getting-syntax-e inside a case statement I don't know how to make it work. myservice contains: #!/bin/sh #/etc/init.d/myservice ### BEGIN INIT INFO # Provides: myservice # Required-Start: $remote_fs $syslog $network # Required-Stop: $remote_fs $syslog # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: my service # Description: Start the myservice service ### END INIT INFO case "$1" in start) # start processes # Import the following variables from config.conf: cfgfile, dir, bindir source <(grep myservice /opt/mysoftware/config.conf | grep -oP '.*(?= #)') if [ -f $cfgfile ] then echo "Starting myservice" /usr/bin/screen -U -d -m $bindir/myscript.sh $cfgfile else echo "myservice could not start because the file $cfgfile is missing" fi ;; stop) # kill processes echo "Stopping myservice" screen -ls | grep Detached | cut -d. -f1 | awk '{print $1}' | xargs kill ;; restart) # kill and restart processes /etc/init.d/myservice stop /etc/init.d/myservice start ;; *) echo "Usage: /etc/init.d/myservice {start|stop|restart}" exit 1 ;; esac exit 0 The file config.conf is a list of variable declarations with a short description and the name of the script using them. I use grep filters to source only the variables I need for a given script. It looks like this: var1=value # path to tmp folder myservice var2=value # log file name myservice script1.sh script2.sh var3=value # prefix for log file script1.sh script2.sh Note: The service worked fine before I convert
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 http://askubuntu.com/questions/422492/why-script-with-bin-bash-is-working-with-bin-sh-not 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 syntax error best answers are voted up and rise to the top Why script with /bin/bash is working, with /bin/sh not? up vote 1 down vote favorite My friend asked me why this two simple script are not working in both shells: Test File "abc.txt": aaa 111 bbb 111 ccc 111 ddd Script #1 (a): #!/bin/sh while read -r line ; do echo "Processing $line" done < <(grep 111 syntax error near abc.txt) Output: ./a: line 4: syntax error near unexpected token `<' ./a: line 4: `done < <(grep 111 abc.txt)' Script #2 (b): #!/bin/bash while read -r line ; do echo "Processing $line" done < <(grep 111 abc.txt) Output: Processing 111 Processing 111 Processing 111 I checked bash and sh on my machine and if I understand this correct this is the same thing. /bin/sh is just a link to /bin/bash: -rwxr-xr-x 1 root root 938736 May 10 2012 bash lrwxrwxrwx. 1 root root 4 Feb 13 10:20 sh -> bash Can someone explain me where is the difference? bash scripts share|improve this question asked Feb 18 '14 at 8:53 Wolfy 2,52862435 2 difference-between-bin-sh-and-bin-bash: askubuntu.com/questions/141928/… –cptPH Feb 18 '14 at 9:08 add a comment| 2 Answers 2 active oldest votes up vote 3 down vote accepted It's because Bash behaves differently when $0 is sh. From Bash's behaviour [Bash Hackers Wiki]: SH mode When Bash starts in SH compatiblity mode, it tries to mimic the startup behaviour of historical versions of sh as closely as possible, while conforming to the POSIX® standard as well. The profile files read are /etc/profile and ~/.profile, if it's a login shel