Solved Can I use export command in script instead of specifying locale on each line?

Solved issue

CaffeineAddict

Well-Known Member
Joined
Jan 21, 2024
Messages
2,499
Reaction score
2,045
Credits
20,243
I have multiple lines that look like this for example:
Bash:
time LC_ALL='C' dos2unix --force --newfile "${WORDLIST}" "${WORDLIST}-unix.lst"
Here I use LC_ALL='C to force command to use "C" locale.

However since I have plenty of such commands it seems redundant to use this method on each line, so I'm considering something like this:

Instead of this:
Bash:
time LC_ALL='C' command1
time LC_ALL='C' command2
time LC_ALL='C' command3
time LC_ALL='C' command4
time LC_ALL='C' command5

I want this:

Bash:
export LC_ALL='C

time command1
time command2
time command3
time command4
time command5

Will I achieve same effect with this second approach?
Will export LC_ALL='C apply to all subsequent commands?

Note that this will be inside a shell script.
 


You only have to do it once.
Code:
#!/bin/bash

export LC_ALL='C'

time command1
time command2
time command3
time command4
time command5

Will include it for every command after that.
 
If you wanted to make sure your variable made it all the way through your script, you could add a...
Code:
echo $C

...at the end after all the commands have finished.
 
Moved to Command Line, where scripting inquiries are stored.

Wizard
 



Top