0

MY goal is to call the following command:

(echo "test";uuencode testfile1.txt testfile1.txt;uuencode testfile2.txt testfile2.txt)|mail -s "subject" "[email protected]"

calling it in the shell works as expected.

However, I would like to do so, when the uuencode commands are stored in an array:

ARR=("uuencode testfile1.txt testfile1.txt" "uuencode testfile2.txt testfile2.txt")

I've tried the following:

STR=$(IFS=';'; echo "${ARR[*]}");
(echo "test";"$STR")|mail -s "subject" "[email protected]"

but I keep on getting the following error:

uuencode testfile1.txt testfile1.txt;uuencode testfile2.txt testfile2.txt: command not found

How to fix this?

I guess it is not recognizing ; as a command separator

1
  • Storing the commands like that is fundamentally wrong. Can you give a more realistic example of multiple commands so that we can suggest a better solution? Commented Oct 19, 2016 at 15:57

1 Answer 1

1

Looks like you are storing each command as a string in the array and joining them into a larger string. You can do an eval on the string to execute.

(echo "test";eval "$STR")|mail -s "subject" "[email protected]"
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.