linux - How to code bash script to allow entire commands with spaces? -
so basically, i'm looking way make below bash script work without issue. each of commands works when tested individually, it's in actual script has problem. code below:
#!/bin/bash answer="$(/usr/bin/grep "permitrootlogin yes" /etc/ssh/sshd_config)" if [ $answer ]; (perl -pi -e \'s/\"permitrootlogin yes\"/\"permitrootlogin no\"/g\' /etc/ssh/sshd_config) else echo "root login not permitted, no values changed." fi
here's happens when try run it:
test.sh: line 9: [: permitrootlogin: unary operator expected root login not permitted, no values changed.
so basically, rather doing find/replace want on file via perl command, it's trying interpret separate instruction.
all attempting @ /etc/ssh/sshd_config
file , change relevant entry yes no if "answer" found yes.
i'm looking way make work. i've looked @ lot of bash examples on site none of them seem cover specific case.
also, reason i'm using perl
sed
works oddly on solaris 11, or isn't installed on extremely old versions, , perl
installed on every version 8 forward.
any ideas?
double quote variable in square brackets.
if [ "$answer" ] ;
otherwise, it's expanded , word-split, [
doesn't know 2 words (it expects first 1 unary operator -f
error's telling you).
Comments
Post a Comment