Monday, June 8, 2009

linux: setting your machine's hostname properly

To setup the hostname manually on a Fedora or RedHat box, you need to edit two files:
  • /etc/sysconfig/network
  • /etc/hosts
1.  In the /etc/sysconfig/network file, modify the hostname:
NETWORKING=yes
HOSTNAME=fedora.hacking.com
GATEWAY=10.7.0.1
  2.  In the /etc/hosts file, modify the hostname:
# Do not remove the following line, or various programs
# that require network functionality will fail.
127.0.0.1 fedora.hacking.com fedora localhost.localdomain localhost

After making these changes to these files, the changes to the hostname should be permanent ( i.e. it will persist even across reboots). Otherwise, simply setting the hostname with the "hostname" command only affects the current session, and you lose the hostname change after the next machine reboot.

Wednesday, June 3, 2009

linux basics: ${var} vs $var

The "$" character introduces parameter expansion, command substitution, or arithmetic expansion. The parameter name or symbol to be expanded may be enclosed in braces, which are optional but serve to protect the variable to be expanded from characters immediately following it which could be interpreted as part of the name.

The basic form of parameter expansion is "${PARAMETER}". The value of "PARAMETER" is substituted. The braces are required when "PARAMETER" is a positional parameter with more than one digit, or when "PARAMETER" is followed by a character that is not to be interpreted as part of its name.

In other word, as a safety measure, always prefer ${var} over $var in your shell scripts.

source