Automator AppleScript - trying to echo a string variable to Bash - applescript

I am trying to create a service using Automator.
Inside a Run AppleScript action I have a variable that is a string in which each line is a word separated by linefeed. Like this:
à
às
a
ante
ao
aos
após
aquela
When I try to echo this to terminal by doing:
do shell script "echo " & (finalText as string)
I get this error:
The action “Run AppleScript” encountered an error: “sh: line 1: a: command not found
sh: line 2: à: command not found
sh: line 3: ante: command not found
...
sh: -c: line 30: syntax error near unexpected token `do'
sh: -c: line 30: `do'”
Any ideas?

To get rid of the command not found type errors in this case, and just about anytime when passing a variable to a do shell script command, use:
do shell script "echo " & finalText's quoted form
You can also use:
do shell script "echo " & quoted form of finalText
Whichever you prefer as appropriate.

Related

Jenkins file execution error while running shell commands

The below code is being used to trigger a shell command using Jenkins file.
sh """
val=\$(echo ${val} | sed 's/[^a-zA-Z0-9]//g')
echo ${val}
"""
The below error reflects as part of the code :
/home/me/#tmp/abcd/script.sh: command substitution: line 4: syntax error near unexpected token `('
Any solution to the same ? Thanks in advance!

Call a ps1 file from a sh script

I have a sh file running that calls a ps1 file in the end sh /test/ps1 . The PowerShell file sends an alert email saying that the script is complete. Not really sure why its throwing syntax error.
Following errors when bash is calling powershell test.ps1
./TEST.PS1: line 4: -t: command not found
./TEST.PS1: line 6: =: command not found
./TEST.PS1: line 7: To: command not found
./TEST.PS1: line 8: SmtpServer: command not found
./TEST.PS1: line 9: From: command not found
./TEST.PS1: line 10: Priority: command not found
./TEST.PS1: line 11: syntax error near unexpected token `}'
./TEST.PS1: line 11: `}'
Also I tried to run the following command on bash but hitting errors as well:
git send-email --f from#email.com --t to#email.com --smtp-server ##.###.###. ~/patches/*.patch

Syntax error for '&' in a remote command

I want to ssh to a node and run a program in a background using &. So, the script looks like
#!/bin/bash
ssh NODENAME 'lmgrd -c license.lic &;
exit;'
However, the bash interpreter complains for syntax error near unexpected token ;. It seems that &
& already finisheds a command. So after & you simply don't use any terminator.

Error on cron job, but working fine on shell

I am configuring Cron to backup my sql automatically. However I think that Cron has some issues and it's not working well.
This is the command I am running:
mysqldump --opt -Q -uhereisthename -p'hereisthepasswordwithstrangecharactersthatmustbeescaped' databasename | gzip > /home2/username/backups/backupnamefolder/backupdbwebsitename.`date +"%Y-%m-%d"`.gz
When I run it via SSH it works fine and generates the backup.
However if I run it via Cron, I get the following error:
/bin/sh: -c: line 0: unexpected EOF while looking for matching `''
/bin/sh: -c: line 1: syntax error: unexpected end of file
Anybody can suggest what's wrong?
Cron treats % as a special character (meaning "new line", hence the references to lines 0 and 1 in the error message). You need to escape it:
date "+\%Y-\%m-\%d"
By the way, the posix $( ) syntax is generally better than backticks - it allows nested commands.

Why do I get "unexpected token `;'?

I would like to run a few instances of my bash script foo.bash in background.
When I write for i in {1..10}; do ~/bin/foo.bash & ; done in the command line I get an error: bash: syntax error near unexpected token ;
Could you explain why this error occurs and how to fix the command?
& and ; are both command separators; you don't need (and can't have) both.
for i in {1..10}; do ~/bin/foo.bash & done

Resources