0

I try to declare an array over ssh with command:

 ssh root@myserver " declare -a users=( user1 user2 user3 user4 user5 ); for user in ${users[*]}; do /usr/sbin/userdel -r $user; done "

When I execute this command, I receive an error like:

sh: syntax error at line 1: `(' unexpected

So what is my mistake?

Thanks.

2
  • 2
    The error indicates that you're running sh and not bash on the remote server. Does that help? Hint: sh doesn't support arrays. Commented Jan 23, 2015 at 20:35
  • Yes. This should be the reason. So I will write a separate script and will pass to remote bash shell by: ssh [user]@[server] 'bash -s' < myscript.sh Thanks for answer. Commented Jan 23, 2015 at 21:01

1 Answer 1

1

I resolved my problem by using:

ssh [user]@[server] 'bash -s' < myscript.sh
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.