Jump to content

echo command not consistent when outputting newline


samispade
 Share

Recommended Posts

The echo command when used in a external bash strip doesn't append a newline. Putting the same script in a Run Script box does append a newline. This can affect how subsequent scripts work.

 

I know that you can use echo -n to remove the newline, once you realise what the problem is, but shouldn't both methods be consistent?

 

 

Alfred 2.0.2 (178)

OS X 10.8.3

Link to comment
Share on other sites

 

The echo command when used in a external bash strip doesn't append a newline. Putting the same script in a Run Script box does append a newline. This can affect how subsequent scripts work.

 

I know that you can use echo -n to remove the newline, once you realise what the problem is, but shouldn't both methods be consistent?

 

 

Alfred 2.0.2 (178)

OS X 10.8.3

 

I tested this quite a few ways and have not been able to replicate the behavior you are suggesting.

 

The default functionality of echo adds the newline. I tested this in a workflow using just an echo command, and calling an external script. I got the same result. I also received the same results performing an echo from the command line and using a script from the command line.

 

If you need to echo something and not have the newline character added then do as you said and use echo -n, or you could use printf instead of echo.

Link to comment
Share on other sites


I set up a simple workflow consisting of a keyword input box feeding into a "Run Script" action box set to osascript.

 

The script inside the box is :-

set theResult to do shell script "bash test.sh"
set the clipboard to "start " & theResult & " end"

 

 
Script test.sh is:-
echo "TestExternal"

 

When run there is no newline added,as the clipboard contains:-

 

 

start TestExternal end

 

To test the "internal" echo command, change the "Run Script" action box to bash and change the script to:-

echo "TestInternal"

 

 

Feed the output of this into a "Run Script" output box set to osascript. The script inside this is :-

set theResult to"{query}"
set the clipboard to "start " & theResult & " end"

 

 

 

When this is run a newline is added, shown by the clipboard:-

 

 

start TestInternal

 end

Link to comment
Share on other sites


I set up a simple workflow consisting of a keyword input box feeding into a "Run Script" action box set to osascript.

 

The script inside the box is :-

set theResult to do shell script "bash test.sh"
set the clipboard to "start " & theResult & " end"

 

 
Script test.sh is:-
echo "TestExternal"

 

When run there is no newline added,as the clipboard contains:-

 

 

start TestExternal end

 

 

start TestInternal

 end

 

I get this same behaviour running the AppleScript in AppleScript editor so it looks like AppleScript is trimming off the newlines in the return from the bash script. Alfred doesn't process the text you are returning so this is a script issue rather than an Alfred issue. The safest bet is to ensure that whatever you are echoing out of a Run Script to be passed onwards is the exact text you need.

 

I'm moving this to closed to keep Alfred's bugs area focused.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...