Skip to main content
deleted 47 characters in body
Source Link
Jeff Schaller
  • 68.8k
  • 35
  • 122
  • 264

I have a bash script [.sh file] Thescript; the script is to generate a random number and user have tothe user guess it.

printf 'Guess the number (1-10) : '
read -r n
randint=$(( ( RANDOM % 10 )  + 1 ))
if [ $n = $randint ];
then
echo "You Won !"
else
echo "Sorry, try again !"
fi

It works, but in the next script I have encoded this code into bas64base64 and tried to run it using the following code.

exec="cHJpbnRmICdHdWVzcyB0aGUgbnVtYmVyICgxLTEwKSA6ICcKcmVhZCAtciBuCnJhbmRpbnQ9JCgoICggUkFORE9NICUgMTAgKSAgKyAxICkpCgppZiBbICRuID0gJHJhbmRpbnQgXTsKdGhlbgplY2hvICJZb3UgV29uICEiCmVsc2UKZWNobyAiU29ycnksIHRyeSBhZ2FpbiAhIgpmaQ=="
base64 -d <<< $exec | sh

It gives anthis error [Cygwin Terminal] in a Cygwin Terminal:

Guess the number (1-10) : sh: line 4: [: too many arguments
Sorry, try again !

I tried an online compiler and it failed also:

sh: 5: [: =: unexpected operator

I dontdon't know what to do i am tired of searching google. Hope somebody seefix this  .

I have a bash script [.sh file] The script is to generate a random number and user have to guess it.

printf 'Guess the number (1-10) : '
read -r n
randint=$(( ( RANDOM % 10 )  + 1 ))
if [ $n = $randint ];
then
echo "You Won !"
else
echo "Sorry, try again !"
fi

It works but in the next script I have encoded this code into bas64 and tried to run it using following code.

exec="cHJpbnRmICdHdWVzcyB0aGUgbnVtYmVyICgxLTEwKSA6ICcKcmVhZCAtciBuCnJhbmRpbnQ9JCgoICggUkFORE9NICUgMTAgKSAgKyAxICkpCgppZiBbICRuID0gJHJhbmRpbnQgXTsKdGhlbgplY2hvICJZb3UgV29uICEiCmVsc2UKZWNobyAiU29ycnksIHRyeSBhZ2FpbiAhIgpmaQ=="
base64 -d <<< $exec | sh

It gives an error [Cygwin Terminal] :

Guess the number (1-10) : sh: line 4: [: too many arguments
Sorry, try again !

I tried online compiler and failed also

sh: 5: [: =: unexpected operator

I dont know what to do i am tired of searching google. Hope somebody see this  .

I have a bash script; the script is to generate a random number and have the user guess it.

printf 'Guess the number (1-10) : '
read -r n
randint=$(( ( RANDOM % 10 )  + 1 ))
if [ $n = $randint ];
then
echo "You Won !"
else
echo "Sorry, try again !"
fi

It works, but in the next script I have encoded this code into base64 and tried to run it using the following code.

exec="cHJpbnRmICdHdWVzcyB0aGUgbnVtYmVyICgxLTEwKSA6ICcKcmVhZCAtciBuCnJhbmRpbnQ9JCgoICggUkFORE9NICUgMTAgKSAgKyAxICkpCgppZiBbICRuID0gJHJhbmRpbnQgXTsKdGhlbgplY2hvICJZb3UgV29uICEiCmVsc2UKZWNobyAiU29ycnksIHRyeSBhZ2FpbiAhIgpmaQ=="
base64 -d <<< $exec | sh

It gives this error in a Cygwin Terminal:

Guess the number (1-10) : sh: line 4: [: too many arguments
Sorry, try again !

I tried an online compiler and it failed also:

sh: 5: [: =: unexpected operator

I don't know to fix this.

Became Hot Network Question
edited tags
Source Link

I have a bash script [.sh file] The script is to generate a random number and user have to guess it.

printf 'Guess the number (1-10) : '
read -r n
randint=$(( ( RANDOM % 10 )  + 1 ))
if [ $n = $randint ];
then
echo "You Won !"
else
echo "Sorry, try again !"
fi

It works but in the next script I have encoded this code into bas64 and tried to run it using following code.

exec="cHJpbnRmICdHdWVzcyB0aGUgbnVtYmVyICgxLTEwKSA6ICcKcmVhZCAtciBuCnJhbmRpbnQ9JCgoICggUkFORE9NICUgMTAgKSAgKyAxICkpCgppZiBbICRuID0gJHJhbmRpbnQgXTsKdGhlbgplY2hvICJZb3UgV29uICEiCmVsc2UKZWNobyAiU29ycnksIHRyeSBhZ2FpbiAhIgpmaQ=="
base64 -d <<< $exec | sh

It gives an error [Cygwin Terminal] :

Guess the number (1-10) : sh: line 4: [: too many arguments
Sorry, try again !

I tried online compiler and failed also

sh: 5: [: =: unexpected operator

I dont know what to do i am tired of searching google. Hope somebody see this .

I have a bash script. The script is to generate a random number and user have to guess it.

printf 'Guess the number (1-10) : '
read -r n
randint=$(( ( RANDOM % 10 )  + 1 ))
if [ $n = $randint ];
then
echo "You Won !"
else
echo "Sorry, try again !"
fi

It works but in the next script I have encoded this code into bas64 and tried to run it using following code.

exec="cHJpbnRmICdHdWVzcyB0aGUgbnVtYmVyICgxLTEwKSA6ICcKcmVhZCAtciBuCnJhbmRpbnQ9JCgoICggUkFORE9NICUgMTAgKSAgKyAxICkpCgppZiBbICRuID0gJHJhbmRpbnQgXTsKdGhlbgplY2hvICJZb3UgV29uICEiCmVsc2UKZWNobyAiU29ycnksIHRyeSBhZ2FpbiAhIgpmaQ=="
base64 -d <<< $exec | sh

It gives an error [Cygwin Terminal] :

Guess the number (1-10) : sh: line 4: [: too many arguments
Sorry, try again !

I tried online compiler and failed also

sh: 5: [: =: unexpected operator

I dont know what to do i am tired of searching google. Hope somebody see this .

I have a bash script [.sh file] The script is to generate a random number and user have to guess it.

printf 'Guess the number (1-10) : '
read -r n
randint=$(( ( RANDOM % 10 )  + 1 ))
if [ $n = $randint ];
then
echo "You Won !"
else
echo "Sorry, try again !"
fi

It works but in the next script I have encoded this code into bas64 and tried to run it using following code.

exec="cHJpbnRmICdHdWVzcyB0aGUgbnVtYmVyICgxLTEwKSA6ICcKcmVhZCAtciBuCnJhbmRpbnQ9JCgoICggUkFORE9NICUgMTAgKSAgKyAxICkpCgppZiBbICRuID0gJHJhbmRpbnQgXTsKdGhlbgplY2hvICJZb3UgV29uICEiCmVsc2UKZWNobyAiU29ycnksIHRyeSBhZ2FpbiAhIgpmaQ=="
base64 -d <<< $exec | sh

It gives an error [Cygwin Terminal] :

Guess the number (1-10) : sh: line 4: [: too many arguments
Sorry, try again !

I tried online compiler and failed also

sh: 5: [: =: unexpected operator

I dont know what to do i am tired of searching google. Hope somebody see this .

Source Link

running base64 encoded bash script gives me error

I have a bash script. The script is to generate a random number and user have to guess it.

printf 'Guess the number (1-10) : '
read -r n
randint=$(( ( RANDOM % 10 )  + 1 ))
if [ $n = $randint ];
then
echo "You Won !"
else
echo "Sorry, try again !"
fi

It works but in the next script I have encoded this code into bas64 and tried to run it using following code.

exec="cHJpbnRmICdHdWVzcyB0aGUgbnVtYmVyICgxLTEwKSA6ICcKcmVhZCAtciBuCnJhbmRpbnQ9JCgoICggUkFORE9NICUgMTAgKSAgKyAxICkpCgppZiBbICRuID0gJHJhbmRpbnQgXTsKdGhlbgplY2hvICJZb3UgV29uICEiCmVsc2UKZWNobyAiU29ycnksIHRyeSBhZ2FpbiAhIgpmaQ=="
base64 -d <<< $exec | sh

It gives an error [Cygwin Terminal] :

Guess the number (1-10) : sh: line 4: [: too many arguments
Sorry, try again !

I tried online compiler and failed also

sh: 5: [: =: unexpected operator

I dont know what to do i am tired of searching google. Hope somebody see this .