Jump to content

Help with a basic shell script


Guest BooYah
 Share

Recommended Posts

I have this script to open a Japanese terminal, but as soon as it's finished, ther terminal language resets to English. If I type the commands 1 by 1, the langauge stays Japanese. Why won't it stay Japanese if I use the script?

 

#! /bin/bash

# A script to open a Japanese console

echo "Setting-up Japanese Console"

export LC_ALL=ja_JP

export LANG=ja_JP.eucJP

export XMODIFIERS='@im=kinput2'

kinput2 -wnn &

echo $LANG

Link to comment
Share on other sites

I have this script to open a Japanese terminal, but as soon as it's finished, ther terminal language resets to English. If I type the commands 1 by 1, the langauge stays Japanese. Why won't it stay Japanese if I use the script?

For one very simple reason - you can't pass environment variables "back" to parents - only "forward" to children. When you run the script, a separate shell is run, which gets all those variables ( LANG and such). When you run commands one by one, your current shell variables are reassigned.

#! /bin/bash

This /bin/bash runs to execute your script!!!

# A script to open a Japanese console

echo "Setting-up Japanese Console"

export LC_ALL=ja_JP

export LANG=ja_JP.eucJP

export XMODIFIERS='@im=kinput2'

And these variables would never get to your login shell!!!

kinput2 -wnn &

echo $LANG

 

There is a way, though, to leave your terminal in Japanese.

Don't run the script, but "source" it.

. your_script_here

And yes, it is exactly that : "dot space script name" :-)

This way, your login shell and not a separate shell would run the script - the effect would be the same as of typing the commands one by one.

Good luck!

Link to comment
Share on other sites

That's pretty cool, I didn't know about the . script file. I've used 

 

source filename

 

with the full word source. Is that the same thing in terms of process environment variables?

EXACTLY the same, both "." and "source" are synonyms in bash.

 

Both are bash builtins, and both are intended to read and execute commands from "filename" (as in "source filename" or ". filename") in the CURRENT SHELL CONTEXT; vs a normal script execution which creates a subshell.

chalex20 explained it perfectly

 

Side note: For what I know "." was a Bourne Shell Builtin, and "source" came later as a Bash Builtin, so if you want the maximun portability in a script you should use "." instead of "source" (It's me speaking? :shock: well, it could be comp.unix.shell's fault --- my new 'divetimento' )

Link to comment
Share on other sites

Side note: For what I know "." was a Bourne Shell Builtin, and "source" came later as a Bash Builtin, so if you want the maximun portability in a script you should use "." instead of "source" (It's me speaking?  :shock:  well, it could be comp.unix.shell's fault --- my new 'divetimento' )

source comes originally from the csh/tcsh land :-)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

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.

Loading...
 Share

×
×
  • Create New...