例1:#!/bin/bash
touch hello.c
echo "#include<stdio.h>" >hello.c
echo "int main()" >>hello.c
echo "{" >>hello.c
echo‘printf("Hello World!\n");’ >>hello.c
echo "return 0;" >>hello.c
echo "}" >>hello.c
gcc hello.c -o hello
./hello
例2:#!/bin/bash
a="hello world"
echo those are $a
echo $0
echo $1
echo $2
echo $*
echo $#
例3:#!bin/bash
for dir in $1 $2 $3
do
mkdir $dir
cd $dir
touch $dir.txt
echo "hello $dir" > $dir.txt
cd ..
例4:#!/bin/bash
hello="hello world"
func1()
{
echo "hello"
}
func2()
{
echo "world“
}
func1
func2
echo ${hello}
例5:#!/bin/bash
DIR="/home/123"
FILE="/home/123/1"
if [-d $DIR]; then
echo "$DIR"
fi
if [-f $FILE]; then
echo "$FILE"
fi