Jump to content
himat

Bash not working properly

Recommended Posts

Posted (edited)

I tried running this script in a workflow

 

 

#!/usr/local/bin/bash


string="a FeW WOrdS"
string=${string,,}

echo "$string"

 

 

But then in the Alfred workflow debugger, I get 

 

 

/Users/me/Library/Caches/com.runningwithcrayons.Alfred/Workflow Scripts/A4DF2A96-E3FC-4D43-BAEC-BD9CDFAA265E: line 10: ${string,,}: bad substitution

 

This script works in my normal terminal, so why doesn't it work in an Alfred script?

 

 

Edited by himat

Share this post


Link to post

It looks like it's being run with /bin/bash in Alfred, not /usr/local/bin/bash. /bin/bash is an older version and doesn't support that syntax.

 

Presumably you've pasted that script in a Script box with Language = /bin/bash. If you want to run a script with /usr/local/bin/bash, you need to save it as a separate file.

Share this post


Link to post

Making it a script fixed that problem, but it seems there's still some problem with used `sed` in alfred.

 

string="helLO tHEre"
echo "$string" | sed 's/.*/\L&/'

This works in the terminal and outputs "hello there".

 

But when I run (even as an external script) within Alfred, it outputs "LhelLO tHEre". 

Why doesn't this work?

Share this post


Link to post

We can't really diagnose issues with workflows that we don't have. Please upload the actual workflow somewhere and post a link to it.

 

 

Share this post


Link to post

Here's the workflow: https://www.dropbox.com/s/18e6nwg6om4yymh/snippets with scripts.alfredworkflow?dl=0

 

You should copy some text to your clipboard, then type ".title", and the text should be turned into title case, but it doesn't work within alfred for some reason.

 

  1. Alfred 4.0.7 [1131]
  2. macOS Mojave 10.14.5 
  3. System bash (via `bash --version` in terminal): GNU bash, version 5.0.2(1)-release (x86_64-apple-darwin17.7.0)

Thank you

Share this post


Link to post

It doesn't work because you've apparently reconfigured your shell to use a non-standard  sed. Presumably, you've installed gnu-sed via Homebrew and have that setup at /usr/local/bin/sed.


When you run sed in Alfred, you get the default version at /usr/bin/sed.


Alfred doesn't use your shell environment because it isn't launched from your shell, so /usr/local/bin isn't on PATH in Alfred. If you want to run /usr/local/bin/sed from Alfred, you have to call it as /usr/local/bin/sed, not just sed, or if you're running a whole bunch of stuff from /usr/local/bin, put export PATH=/usr/local/bin:$PATH at the top of your script.

Share this post


Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...