Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

While executing the below script, I'm getting an error:

Syntax error at line 1 : `(' is not expected.

sudo su - user1 -c "cd $HOME ; tar -cvf $HOME/mine.tar `cat /tmp/$LOGNAME/List`  "

where List file contains the name of some other files.

Please help me out with some solution.

Regards, Sumit

share|improve this question – djangofan Jun 25 '13 at 22:57
Standard debugging technique: break down the problem until you find the smallest example that causes it. What happens if you say sudo su - user1 -c date? How about sudo su - user1 -c sh and then type cd $HOME ; tar -cvf $HOME/mine.tar `cat /tmp/$LOGNAME/List` into the shell? – Scott Jun 25 '13 at 23:01
question also on stackoverflow – glenn jackman Jun 25 '13 at 23:35
Why the cd $HOME ? You already have an -f $HOME/mine.tar in the command. – Hennes Dec 23 '13 at 14:43

Your shell is expanding things too early.

Does $LOGNAME have a ( in it? Or the contents of /tmp/$LOGNAME/List?

Bash will expand $HOME and $LOGNAME before they get passed to su - when su then tries to pass them off to sh or bash, they have improper tokens in them.

share|improve this answer

Please make that single line commands to multiple line and execute, like write this to

#!/usr/bin/env bash
cd $HOME
tar -cvf $HOME/mine.tar
cat /tmp/$LOGNAME/List

Give execution permission (chmod +x and run that script as sh path to the file(

e.g: sh /home/

share|improve this answer
Two minor points: 1) No need to make it executable or add the shebang line if you run it with sh scriptfile. 2) sh might not be bash, so in this example sh and /home/ might run under different shells. This matters for more complex scripts which may try to use bash-only features. – Hennes Dec 23 '13 at 14:45
I mention that in the case of bash. – mailer Dec 24 '13 at 2:23

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .