Bash

From wiki
Revision as of 23:19, 18 October 2013 by Administrator (talk | contribs) (Created page with "<pre> #!/bin/bash echo -n "Enter the name of an animal: " read ANIMAL echo -n "The $ANIMAL has " case $ANIMAL in horse | dog | cat) echo -n "four";; man | kangaroo ) echo -n...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search
#!/bin/bash
echo -n "Enter the name of an animal: "
read ANIMAL
echo -n "The $ANIMAL has "
case $ANIMAL in
 horse | dog | cat) echo -n "four";;
 man | kangaroo ) echo -n "two";;
 *) echo -n "an unknown number of";;
esac
echo " legs."

select fname in *;
do
	echo you picked $fname \($REPLY\)
	break;
done

echo a{d,c,b}e

echo {0,1}{0,1}{0,1}
#!/bin/bash
echo "Input 5 integers [0-100]"
read a
read b
read c
read d
read e
echo "$((($a+$b+$c+$d+$e)/5))"
for i in {0780..1063}; do echo `printf "%04d" $i`; done

1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063

/usr/bin/4chan

#!/bin/bash
ID=$(echo $1 | grep -o 'res/[^"]*' | egrep "[0-9]{1,}" -o );
if [ -d $ID ]; then
echo $ID folder exists
cd $ID
curl $1 | grep -o 'File[^"]*<a href=\"//images.4chan.org/[^"]*' | grep -o '//images.4chan.org/[^"]*' > imgurl2.x
for line in $(cat imgurl2.x); do echo "http:"$line >> imgurlnew.x; done;
comm -13 imgurl.x imgurlnew.x > diff.x
wget -i diff.x
cat diff.x >> imgurl.x
rm diff.x
rm imgurlnew.x
rm imgurl2.x
cd ..
else
echo $ID folder does not exist
mkdir $ID
cd $ID
curl $1 | grep -o 'File[^"]*<a href=\"//images.4chan.org/[^"]*' | grep -o '//images.4chan.org/[^"]*' > imgurl2.x
for line in $(cat imgurl2.x); do echo "http:"$line >> imgurl.x; done;
wget -i imgurl.x
rm imgurl2.x
cd ..
#!/bin/bash
URL=$(echo $1)
if [[ "$URL" !=  *'#'* ]]; then
        ID=$(echo $URL | grep -o 'res/[^"]*' | egrep "[0-9]{1,}" -o );
else
        ID=$(echo $URL | grep -o 'res/[^"]*\#' | egrep "[0-9]{1,}" -o );
fi
if [ -d $ID ]; then
        echo $ID folder exists
        cd $ID
else
        echo $ID folder does not exist
        mkdir $ID
        cd $ID
fi
curl $URL | grep -o 'File[^"]*<a href=\"//images.4chan.org/[^"]*' | grep -o '//images.4chan.org/[^"]*' > imgurlpre.x
for line in $(cat imgurlpre.x); do echo "http:"$line >> imgurl.x; done;
rm imgurlpre.x;
for line in $(cat imgurl.x); do wget -nc $line; done;
rm imgurl.x

cd ..
#!/bin/bash
URL=$(echo $1)
if [[ "$URL" !=  *'#'* ]]; then
        ID=$(echo $URL | grep -o 'res/[^"]*' | egrep "[0-9]{1,}" -o );
else
        ID=$(echo $URL | grep -o 'res/[^"]*\#' | egrep "[0-9]{1,}" -o );
fi
if [ -d $ID ]; then
        echo $ID folder exists
        cd $ID
else
        echo $ID folder does not exist
        mkdir $ID
        cd $ID
fi
curl $URL | grep -o 'File[^"]*<a href=\"//images.4chan.org/[^"]*' | grep -o '//images.4chan.org/[^"]*' > imgurl.x
for line in $(cat imgurl.x); do wget -nc "http:"$line ; done;
rm imgurl.x
cd ..

.bashrc / .profile


# extractions
extract () {
  if [ -f $1 ] ; then
    case $1 in
      *.tar.bz2)   tar xvjf $1    ;;
      *.tar.gz)    tar xvzf $1    ;;
      *.tar.xz)    tar xvJf $1    ;;
      *.bz2)       bunzip2 $1     ;;
      *.rar)       unrar x $1     ;;
      *.gz)        gunzip $1      ;;
      *.tar)       tar xvf $1     ;;
      *.tbz2)      tar xvjf $1    ;;
      *.tgz)       tar xvzf $1    ;;
      *.zip)       unzip $1       ;;
      *.Z)         uncompress $1  ;;
      *.7z)        7z x $1        ;;
      *.xz)        unxz $1        ;;
      *.exe)       cabextract $1  ;;
      *)           echo "\`$1': unrecognized file compression" ;;
    esac
  else
    echo "\`$1' is not a valid file"
  fi
}