#!/bin/bash
STR="Hello World"
echo $STR
#!/bin/bash
HELLO=Hello
function hello {
local HELLO=World
echo $HELLO
}
echo $HELLO
hello
echo $HELLO
#!/bin/bash
the_world_is_flat=true
# ...do something interesting...
if [ "$the_world_is_flat" = true ] ; then
echo 'Be careful not to fall off!'
fi
#!/bin/bash
COUNTER=0
while [ $COUNTER -lt 10 ]; do
echo The counter is $COUNTER
let COUNTER=COUNTER+1
done
#!/bin/bash
for i in $( ls ); do
echo item: $i
done
#!/bin/bash
for i in `seq 1 10`;
do
echo $i
done
#!/bin/bash
COUNTER=20
until [ $COUNTER -lt 10 ]; do
echo COUNTER $COUNTER
let COUNTER-=1
done
#!/bin/bash
T1="foo"
T2="bar"
if [ "$T1" = "$T2" ]; then
echo expresion evaluated as true
else
echo expresion evaluated as false
fi
#!/bin/bash
case $yn in
[YySs]* ) adduser $user; break;;
[Nn]* ) echo no se creo usuario $user; break;;
* ) echo "Elije y/n";;
esac
#!/bin/bash
while true; do
read -p "Do you wish to install this program?" yn
case $yn in
[Yy]* ) make install; break;;
[Nn]* ) exit;;
* ) echo "Please answer yes or no.";;
esac
done
ARRAY=(one two three)
echo ${ARRAY[*]}
one two three
echo $ARRAY[*]
one[*]
echo ${ARRAY[2]}
three
ARRAY[3]=four
echo ${ARRAY[*]}
one two three four
function quit {
exit
}
function e {
echo $1
}
e Hello
e World
quit
echo foo
#!/bin/sh
debInst() {
dpkg-query -Wf'${db:Status-abbrev}' "$1" 2>/dev/null | grep -q '^i'
}
debInst terminator
#!/bin/bash
if [ -d /opt/ ]; then
echo "Sí, sí existe."
else
echo "No, no existe"
fi
#-d -» Comprobar si existe determinado directorio
#-f -» Comprobar si existe determinado archivo
#-w -» Comprobar si determinado archivo tiene permisos de escritura
#-x -» Comprobar si determinado archivo tiene permisos de ejecución.
#if not: if [ ! -d /opt/ ]; then
#!/bin/bash
user=$(whoami)
if [ "$user" == "root" ]; then
isroot=true
echo "Eres Root! :)"
else
isroot=false
echo "No eres root... :'("
exit
fi