#!/bin/bash
#создаем каталог task со вложенными директориями dir1,dir2,dir3,dir4
mkdir -p /tmp/task/dir1 /tmp/task/dir2 /tmp/task/dir3/dir4

#изменяем текущую директорию на task
cd ./task

#создаем пустой файл task/dir2/empty
touch ./dir2/empty

# создаём файл task/dir2/hello.sh с таким содержанием:
# #!/bin/bash
echo '#!/bin/bash' > ./dir2/hello.sh 
# echo "$1, привет!"
echo 'echo "$1, привет!"' >> ./dir2/hello.sh

#устанавливаем для task/dir2/hello.sh права rwxrw-r--
chmod 764 ./dir2/hello.sh

#сохраняем список файлов task/dir2 в task/dir2/list.txt
ls ./dir2 > ./dir2/list.txt

#создадим переменную окруждения "Практическое задание"
PRACTIC = 'Практическое задание'

#копируем содержимое каталога task/dir2 в каталог task/dir3/dir4
cp -r  ./dir2./dir3/dir4


#записываем в task/dir1/summary.txt список файлов с расширением *.txt
#находящихся в task, включая поддиректории
find ./-name "*.txt"> ./dir1/summary.txt

#дописываем в task/dir1/summary.txt содержимое task/dir2/list.txt
cat ./dir2/list.txt >> ./dir1/summary.txt


#определяем переменную окружения NAME со значением "Всем студентам"

export NAME='Всем студентам'


#запускаем task/dir2/hello.sh с переменной окружения NAME в качестве аргумента
#вывод скрипта должен дописаться в файл task/dir1/summary.txt

./dir2/hello.sh $NAME>>./dir1/summary.txt

#перемещаем с переименованием task.dir1/summary.txt в task/Практическое задание
mv ./dir1/summary.txt ./"$PRACTIC"

#выводим на консоль содержимое файла task/Практическое задание
cat ./"$PRACTIC"

#ищем в файле "Практические задание" строки, которые содержат слово "dir" и затем отсортировываем их
grep "dir" ./"$PRACTIC" | sort | uniq

#меняем текущую директорию на родительскую
cd ..
#удаляем директорию task со всем содержимым
rm ./task -rf 

Online Bash Shell

Write, Run & Share Bash code online using OneCompiler's Online Bash Shell for free. It's one of the robust, feature-rich Bash shell available over online and getting started with the OneCompiler's Bash Shell is simple and pretty fast. The editor shows sample boilerplate code when you choose language as Bash. OneCompiler also has reference scripts, where you can look for the sample scripts and start coding.

About Bash

Bash (Bourne Again Shell) is a shell program written by Brian Fox and is an upgraded version of Bourne Shell program 'sh'.

Features

  • Open source GNU project
  • Read and execute the commands from a Shell Script
  • Can be invoked by either single-character command line options (-a, -b, -c, -i, -l, -r, etc. ) or by multi-character command line options also like --help, --debugger,--login, etc.
  • Consists of Key bindings
  • Available in restricted mode for the environment security
  • Contains one-dimensional arrays to manipulate the lists of data.

Syntax help

Variables

name="Foo"
echo $name
echo "$name"
echo "${name}"

Conditional Statements

If

if [ conditional-expression ]  
then  
statements  
fi  

If-else

if [ conditional-expression ]  
then  
   statements  
else  
  statements
fi  

Else-If

if [ conditional-expression ]  
then  
   statements  
elif [ conditional-expression ]  
then  
 statements  
else  
  statements
fi