Saturday, January 29, 2011

BASH : Built-in commands

1. pwd - basic command - prints working directory
2. cd directory- change directory
cd / - goes to the root(absolut) direcotry
cd ../ - goes to the root(absolut) direcotry

cd with no options - current user directory
cd ~ - home directory

3. ls, dir - not a part of bash, helps you in your scripting, not build in commands
4. read test (press ENTER and write a value) - reads a variable and put it to 'test' variable
echo $test - prints the value from variable $test
read firstname lastname (press ENTER and write the 2 values)
echo $firstname $lastname
read -n 3 answer (press ENTER and write 3 letters)
echo $answer
set | grep answer -> result is the value of answer='...'
5. unset $answer
set | grep answer -> results is '_=answer'
Example:

pico testscript.sh
CONTENT of testscript.sh
#!/bin/bash
eco hello word
if the file has no executable rights and you type ./testscript.sh it won't work
source testscript.sh -> runs script even if the file has no executable rights and prints hello world
cat testscript.sh -> prints the content of the file
6. TESTVARIABLE=1
export TESTVARIABLE
set | grep TESTVARIABLE -> prints TESTVARIABLE=1
7. which bash - /bin/bash - build in commands
set | grep PWD -> you can see PWD is the current directory and OLDPWWD is the previous directory. PWD and OLDPWD are updated all the time
cd $OLDPWD

No comments:

Post a Comment