local emailcommand="echo \"${emailfrom}\" mailx -s \"$emailsubject\" -a 'Content-Type:…
- User
local email_command="echo "{email_from}\" | mailx -s \"email_subject" -a 'Content-Type: text/html' "email_recipient\" < \"email_body""
# Add attachment if conditions are met #if [[ "$should_attach" -eq 1 ]]; then # local email_command+=" -a \"$email_attachment\"" #fi # Send email eval "$email_command"eval getting error why?
- Assistant
The issue with your
email_commandmay be due to the way you are attempting to concatenate strings in bash. Specifically, you cannot use+=to concatenate strings in a double-quoted context, and the incorporation of command substitutions and redirection can also cause problems. - User
what eval do? here
- Assistant
The
evalcommand in Bash is used to execute arguments as a shell command. It takes a string of commands as its argument, evaluates the string, and then executes it as if it were a command typed directly into the shell. - User
my eval is inside of a function. i am calling it from anotherbash script
- Assistant
- User
in below can i give text to send it in body not file local email_command="echo "{email_from}\" | mailx -s \"email_subject" -a 'Content-Type: text/html' "email_recipient\" < \"email_body""
- Assistant
- User
i need an if that checks var_f variable is not empty end exists then echo OK
- Assistant
To check if a variable named
var_fis not empty and exists in a Bash script, you can use anifstatement combined with the-ntest. The-noption checks if the string length is greater than zero, effectively validating that the variable is not empty. Here's how you can do it:Example Code
if [[ -n "$var_f" ]]; then echo "OK" else echo "var_f is either empty or not set." fiExplanation
-
[[ -n "$var_f" ]]: This expression checks if the variable has a non-zero length (i.e., it is not empty). If is set and contains a value, it evaluates to true.
-
- User
is there a limit when calling a funtion with source ~/scripts/.functions.sh my upper functions working but lover functions not working even if they are like below function funcTtest() { echo "test" }
- Assistant
- User
there was no erro it all start after i put the code notepad++ then copy paste it to .functions.sh again
- Assistant
- User
i had invalid header when the attachment added in below code # Prepare the email command local command_email="echo "{email_from}\" | mailx -s \"email_subject" -a 'Content-Type: text/html' "email_recipient\" < \"email_body""
# Add attachment if conditions are met if [[ -n "$email_attachment" ]]; then local command_email+=" -a \"$email_attachment\"" ; fi # Send email eval "$command_email" - Assistant