LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-12-2008, 10:49 AM   #1
BlueberryPickles
LQ Newbie
 
Registered: Jul 2008
Posts: 4

Rep: Reputation: 0
Shell won't recognise foreign characters


Hi everyone,

I'm having a nightmare trying to write a shell script that, among other things, changes to a directory that has foreign characters in its name.

From Ubuntu's terminal, I can type:

$ cd Ontology/Top/World/Français/

and it moves me to my Français directory without a problem.

In my shell script, however, when I have:

#!/bin/sh

LC_ALL="fr_FR.UTF-8"

dir="Ontology/Top/World/Français/"

# Move to the top level of the ontology
cd $dir

# Find all of the categories at the top level of the ontology
ls > directories.tmp


I get the error message:

cd: 8: can't cd to Ontology/Top/World/Fran�ais/

Why won't my script let me use the ç character when I can do it without a problem from the terminal?

Help please!
 
Old 07-12-2008, 01:18 PM   #2
b0uncer
LQ Guru
 
Registered: Aug 2003
Distribution: CentOS, OS X
Posts: 5,131

Rep: Reputation: Disabled
I'm not a shell script master when it comes to using locales, but would you need to export the LC_ALL value - did you check that it's actually set?

EDIT: but if LC_ALL is set to that value when you run the script, it should be in use anyway if I'm not mistaken. Just as a guess, does the charset/keymap of your console (which sh uses; not necessarily the same that for example gnome-terminal uses) contain the glyph you're using?

Last edited by b0uncer; 07-12-2008 at 01:23 PM.
 
Old 07-12-2008, 02:07 PM   #3
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

Rep: Reputation: 244Reputation: 244Reputation: 244
or you can use a wildcard
 
Old 07-13-2008, 03:23 AM   #4
Mr. C.
Senior Member
 
Registered: Jun 2008
Posts: 2,529

Rep: Reputation: 63
I had no trouble with the script (I added a mkdir to the script to create the directories for me):

Code:
$ cat doit.sh
#!/bin/sh

LC_ALL="fr_FR.UTF-8"

dir="Ontology/Top/World/Français/"
mkdir -p $dir

# Move to the top level of the ontology
cd $dir

# Find all of the categories at the top level of the ontology
ls > directories.tmp

$ ./doit.sh

$ LC_ALL="fr_FR.UTF-8" ls -R
Ontology/ doit.sh*

./Ontology:
Top/

./Ontology/Top:
World/

./Ontology/Top/World:
Fran\çais/

./Ontology/Top/World/Français:
directories.tmp
My sh is bash-based, perhaps yours is Bourne-shell based, or behaves in compatibility mode with called by /bin/sh. Try changing #!/bin/sh to #!/bin/bash
 
Old 07-14-2008, 03:52 AM   #5
BlueberryPickles
LQ Newbie
 
Registered: Jul 2008
Posts: 4

Original Poster
Rep: Reputation: 0
Tried that, but no success...What did help was to change the foreign characters to character symbols! Not so readable but it worked...
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
ntfs-3g cannot access files with foreign characters dissociative Slackware 3 05-11-2008 10:26 PM
Accented Characters and other "foreign language" Characters Mark_in_Hollywood LQ Suggestions & Feedback 2 04-30-2007 06:10 PM
Centericq foreign characters messed up dlublink Linux - Software 2 02-24-2005 10:14 AM
Foreign Characters in Fedora RC2 bluemak Linux - Newbie 1 08-30-2004 08:37 AM
gnome-terminal and foreign characters b0uncer Linux - Software 0 05-06-2004 01:03 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:24 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration