Jump to content

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
 

 

Link to comment

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.

Link to comment

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 :-)

Link to comment

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  

Link to comment

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.

Link to comment

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
×
×
  • Create New...