User Tools

Site Tools


bash

Bash

Change the Shell Prompt

I found that particularly with Centos 5, that the default shell prompt for root was terrible. It did not show the pwd, user or host!

Before -bash-3.1# ls Showing no present working directory, no current username, no hostname

Syntax PS1='\u@\h:\w\$ ' There are a few other things one can show also. Such as the time, date, FQHN etc. man bash for the full list.

After root@volcano:/tmp# ls

Ref.: http://www.builderau.com.au/program/linux/soa/10-shortcuts-to-master-bash/0,339028299,339279043,00.htm

Function problem in Bash

I recently dist-upgraded a ubuntu server, and one bash script stopped working.

Original

#!/bin/bash

watch ' function yesno(){ case “$1” in

      0)      echo "yes"
      ;;
      1)      echo "no"
      ;;
      *)      echo "error"
      ;;

esac }

Problem

sh: Syntax error: “(” unexpected

Solution

Remove the word function, and call it directly.

#!/bin/bash

watch ' yesno(){ case “$1” in

      0)      echo "yes"
      ;;
      1)      echo "no"
      ;;
      *)      echo "error"
      ;;

esac }

Ref: http://stackoverflow.com/questions/6347119/bash-syntax-error

bash.txt · Last modified: 2022/07/19 20:13 by 127.0.0.1