Thursday, January 27, 2011

Shell Variables are Global by Default

All variables in a shell script are global unless specifically declared as local. Local variables can be used only inside a function.

#!/bin/bash
# Global and local variables

carwash()
{
local vin="17DIGITS"
echo "IN Carwash. Your windscreen is:" $1 "and your VIN is:" $vin
post_carwash_status="BEARY CLEAN"
}

status="DIRTY"
carwash $status
echo "After carwash. Your windscreen is:" $status "and your VIN: " $vin
echo "Post Carwash Status: " $post_carwash_status

OUTPUT

IN Carwash. Your windscreen is: DIRTY and your VIN is: 17DIGITS
After carwash. Your windscreen is: DIRTY and your VIN: 
Post Carwash Status:  BEARY CLEAN
Notice that the local variable vin is not available outside the function.

ps to list only ppid

I generally use ps to get ppid to kill a process and finally figured a way to list just that.

ps -o ppid
And to list ppid without header, indicate that it should have a value. To display more information, add the headings preceded by output formatter -o.

ps -o ppid=
ps -o ppid= args= | grep Firefox 

Friday, January 21, 2011

vi Search backwards

For some reason I couldn't ever remember how to do a backward search in vi. So I would use forward search command, "/pattern" and then do "N" which is fine except the clumsy usage of uppercase.

Backward search can be done with "?pattern" and then do "n" to iterate over all the occurrences. Committed to memory now.

Sunday, November 7, 2010

Could not parse the remainder in django Template

It's caused when we forget we cannot make HTML execute python commands with the exception of filters and tags. So a "for loop" ( a tag) can iterate over list items or dictionary items but create or append a list.

List of some of the filters and tags supported.
http://www.djangobook.com/en/1.0/appendixF/

Thursday, October 28, 2010

When ssh relentlessly keeps asking for password

Check if your from and to home directories plus ssh directory have the correct permissions. All the details here -

Using python shell for django project

If you want to test django code in python shell but are getting error messages regarding environment variables not set; set them by using that project's manage script.
python manage.py shell

Thursday, September 9, 2010

list directories

Listing directories in UNIX korn shell
$ls -d */
Mail/ sourcefiles/ mib/ dir3/
awc/ locks/ targetfiles/ dir4/
bin/ log/ perlo/ z12/