Jump to content
vdesabou

Different behavior when executing ksh script in Alfred and in terminal

Recommended Posts

Hi,

 

I have a difference of behavior when I execute a ksh script in a "Run script" action in Alfred and in a terminal.

 

The code is as following:

SPEC_CHAR="ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþÿ"
NORM_CHAR="AAAAAAACEEEEIIIIDNOOOOOOUUUUYPSaaaaaaaceeeeiiiionoooooouuuuyby"

mystring="têté"
mystring=$(print $mystring | sed 'y/'${SPEC_CHAR}'/'${NORM_CHAR}'/')
echo "$mystring" 

 

When I execute in terminal, I have:

 

/Users/vincent/Downloads>

 

ksh repro.ksh
tete
 
But when I execute it in Alfred (see workflow with reproduction here http://d.pr/f/ShJl ), I get an empty string for $mystring
 
Any idea what's wrong here?
 
Mac OS 10.8.3
Alfred: 2.0.2
Reproducible: Yes
 

 

Share this post


Link to post

I think this may be either an issue with not importing environments or your workflow itself, I am moving into workflow questions so it can get some more eyes on the issue to maybe shed some light.

Share this post


Link to post

Hi,

 

I have a difference of behavior when I execute a ksh script in a "Run script" action in Alfred and in a terminal.

 

The code is as following:

SPEC_CHAR="ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþÿ"
NORM_CHAR="AAAAAAACEEEEIIIIDNOOOOOOUUUUYPSaaaaaaaceeeeiiiionoooooouuuuyby"

mystring="têté"
mystring=$(print $mystring | sed 'y/'${SPEC_CHAR}'/'${NORM_CHAR}'/')
echo "$mystring" 

 

When I execute in terminal, I have:

 

/Users/vincent/Downloads>

 

ksh repro.ksh
tete
 
But when I execute it in Alfred (see workflow with reproduction here http://d.pr/f/ShJl ), I get an empty string for $mystring
 
Any idea what's wrong here?
 
Mac OS 10.8.3
Alfred: 2.0.2
Reproducible: Yes

 

Still not sure of the exact fix, but so far it appears that the issue lies in sed. If I manipulate it to search a single char and replace, it works perfectly. If I change it back to do the full replace that you are attempting, it fails. I'll continue to tinker with it and see what I can find.

Share this post


Link to post

Yes, it seems related to sed indeed, but that's strange that it is only happening when using Alfred.

 

I've simplified the code:

 

Looks like using combination of y/"accented character" is causing the issue:

mystring="Têté"
mystring=$(echo "$mystring" | sed y/ê/e/)
echo "$mystring"

 

is not working

 

If i do:

 

mystring="Têté"
mystring=$(echo "$mystring" | sed y/t/b/)
echo "$mystring"

 

or :

mystring="Têté"
mystring=$(echo "$mystring" | sed s/ê/e/)
echo "$mystring" 

 

 

It is working

 

Weird...

 

Thanks for your help, I'm getting crazy :-)

Share this post


Link to post

Hi David,

 

I believe this is because LANG was not set when invoking the script with Alfred.

 

In terminal, If I do:

$ echo $LANG
fr_FR.UTF-8

$ ksh repro.ksh
tete

$ unset LANG


$ ksh repro.ksh
sed: 1: "y/ÀÁÂÃÄÅÆÇÈÉ� ...": transform strings are not the same length

 

 

So I added in the "repro2" repro.ksh script, export LANG='fr_FR.UTF-8' and now it works!

 

Problem solved. Thanks  

Share this post


Link to post

Hi David,

 

I believe this is because LANG was not set when invoking the script with Alfred.

 

In terminal, If I do:

$ echo $LANG
fr_FR.UTF-8

$ ksh repro.ksh
tete

$ unset LANG


$ ksh repro.ksh
sed: 1: "y/ÀÁÂÃÄÅÆÇÈÉ� ...": transform strings are not the same length

 

 

So I added in the "repro2" repro.ksh script, export LANG='fr_FR.UTF-8' and now it works!

 

Problem solved. Thanks  

 

Awesome! Nice work.

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...