I get this error

(-bash: syntax error near unexpected token `&' )

when I run the command below:

sudochown -hRfwebadmin:www-data /web/<repertoire>&&sudoln -s /web/<repertoire>
/var/www/html/<repertoire>&&sudochown -hRfwebadmin:www-data
/var/www/html/<repertoire>&&sudols -al /var/www/html/

so can someone help what's wrong in the syntax of this command line

  • 8
    There's quite a bit wrong with that command. It's missing spaces, it contains generic placeholders, and it makes no sense. – TheWanderer Jul 2 '16 at 14:09
  • can you recommend the correct one: sudo chown -hRfwebadmin:www-data /web/<repertoire>&&sudo ln -s /web/<repertoire> /var/www/html/<repertoire>&&sudo chown -hRfwebadmin:www-data /var/www/html/<repertoire>&&sudo ls -al /var/www/html/ – tsilokomail Jul 2 '16 at 14:12
  • 2
    Not unless you provide us with what you are trying to do and where you got that command. – TheWanderer Jul 2 '16 at 14:13
  • @Zacharee it is in order to make available a site on the server after uploading it in the /web/ rep, but only the /var/www/html is used to point to this /web for security purpose. so the /var/www/html will link to /web – tsilokomail Jul 2 '16 at 14:20
  • 2
    Please edit your question and explain what <repertoire> is supposed to be. Is that the name of a directory? The < and > symbols have special meanings in the shell so their presence makes your command very hard to understand. When asking a question, you need to explain what you are trying to do. Since your command is very wrong, it is very hard to guess what you meant to say if you don't actually tell us. – terdon Jul 2 '16 at 14:47

I think what you are trying to do is run these commands:

sudo chown -hRf webadmin:www-data /web/repertoire &&
sudo ln -s /web/repertoire /var/www/html/repertoire &&
sudo chown -hRf webadmin:www-data /var/www/html/repertoire &&
sudo ls -al /var/www/html/

The && means "run the next command only if the previous one was successful". It isn't actually needed as such. Also, the second chown command is pointless. The directory /var/www/html/repertoire is a link to /web/repertoire and since you have already changed the ownerhip of the target, there's no point in changing it for the link as well. It has already been changed (that's the point of a link). So, what you really wanted to do is:

sudo chown -hRf webadmin:www-data /web/repertoire 
sudo ln -s /web/repertoire /var/www/html/repertoire
sudo ls -al /var/www/html/
  • thank you for your explanation, i opted for your recommendation: sudo chown -hRf webadmin:www-data /web/repertoire && sudo ln -s /web/repertoire /var/www/html/repertoire && sudo chown -hRf webadmin:www-data /var/www/html/repertoire && sudo ls -al /var/www/html/ no error anymore, will test the result. thanks – tsilokomail Jul 2 '16 at 15:01
  • @tsilokomail What you really want is the second piece of code because the second chown is redundant. – edwinksl Jul 2 '16 at 15:02
  • you are right i have understood. thanks – tsilokomail Jul 2 '16 at 15:07
  • 2
    @tsilokomail If this answer solved your issue, please take a moment and accept it by clicking on the check mark to the left. That will mark the question as answered and is the way thanks are expressed on the Stack Exchange sites. – terdon Jul 2 '16 at 15:12

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.