Archive | Bash RSS feed for this section

Multi lingual support in MySQL/Rails/BASH

16 Apr

We had translations in text files that we needed imported into our mysql database.

Our database had UTF-8 character encoding which is correct.

Swedish characters were appearing like :åäà �
There are a number of issues here:
1. SSH session – if you’re using Putty make sure you’ve set the terminal to be UTF
2. check the type of your file using “file”
3. if necessary use ‘iconv’ to convert to UTF8 – iconv -f ISO-8859-1 -t UTF8 /tmp/fr2.yml
4. Ensure your browser is displaying UNICODE, View->Character Encoding in Firefox
5. If you are using Linux, make sure a UTF LANG is set eg.: export LANG=”en_AU.UTF-8″


Most useful BASH shortcuts

29 Mar

ctrl-r : search through your history
ctrl-a/ctrl-e : go to start/end of line
ctrl-w/alt- : delete previous word
ctrl-t : transpose/swap previous two characters
alt-t : transpose/swap previous two words
ctrl-y : previous delete (like paste)
!$ : “!$” means the last argument of previous command
!^ : “!^” means the first argument of previous command

$   : show all system variables

screen : command to de-couple running program from terminal

good vim tips:


8 Dec

echo “$xworld” #doesn’t work

you have to ‘protect’ your variable:
echo “${x}world” # works!
echo “${x/o/op}” # does a regex on the variable and prints out “hellop”

Bash command prompts

11 Oct

Best prompt:
export PS1=”\[33[36m\][\t]\[33[1;33m\]\u\[33[0m\]@\e[31;1mPRODUCTION:\[33[36m\][\w]:\[33[0m\]”

Favoured stuff:
export PS1=”\[33[36m\][\t]\[33[1;33m\]\u\[33[0m\]@\[\e[32;1m\]\H \e:\[33
alias vi=”/usr/bin/vim”

Standard prompt:
export PS1="\[33[36m\][\t]\[33[1;33m\]\u\[33[0m\]@\h:\[33[36m\][\w]:\[33[0m\]"

I might prefer these colors:

export PS1="\[\e[36;1m\]\u@\[\e[32;1m\]\H \e[31;1mBACKUP> \[\e[0m\]"

Maybe all green:
export PS1="\[33[36m\][\t]\[33[32;1m\]\u\[33[32;1m\]@\h:\[33[32;1m\][\w]:\[33[0m\] "


5 Mar

#simple loop
while [ 1 ]; do ls -al ; done

#another loop

while [ $CNT -lt 10 ];
echo count is $CNT
let CNT=CNT+1

#a for loop, need `seq` to work….
for i in `seq 1 10`; do
echo $i