How to search for user keyboard input in bash shell? I thought it would just work,
int b; scanf("%d", &b);
but he says
- bash: / Users / [name] /. bash_profile: line 17: syntax error near unexpected token ``% d ','- bash: / Users / [name] /. bash_profile: line 17: `scanf ("% d ", & b); ''
- bash: / Users / [name] /. bash_profile: line 17: syntax error near unexpected token ``% d ','
- bash: / Users / [name] /. bash_profile: line 17: `scanf ("% d ", & b); ''
EDIT
backdoor() { printf "\nAccess backdoor Mr. Fletcher?\n\n" read -r b if (( b == 1 )) ; then printf "\nAccessing backdoor...\n\n" fi }
Just use readbuiltin:
read
read -r b
( %d), , () , ; , , , , .
%d
:
(( b == 1 ))
... $b ,
$b
[[ $b = 1 ]]
... b "1".
"1"
Bash, , . , , , , . , :
while read -p "Enter integer: " integer; do [[ "$integer" =~ [[:digit:]]+ ]] && break echo "Not an integer: $integer" >&2 done
, , , .
C Bash.
backdoor() { printf '\n%s\n\n' 'Access backdoor Mr. Fletcher?' read -r b if ((b == 1)) then printf '\n%s\n\n' 'Accessing backdoor...' fi }