У меня есть этот код:
#!/bin/bash
#clear screen
clear
# Ask for name of directory to create
echo "Please enter a directory name"
echo "that you wish to create"
read dir1
# create directory
mkdir $dir1
# change to the newly created directory
cd $dir1
# Tell user where he/she is
echo "This directory is called 'pwd'"
# create some files
touch file1 file2 file3
# put in some content
echo "This is $dir1/file1" > file1
echo "This is $dir1/file2" > file2
echo "This is $dir1/file3" > file3
# announce file names
echo "The files in $dir1 are: "
ls -hl
# show the contents of the files
echo "The content of the files are: "
cat file1
cat file2
cat file3
echo "Goodbye"
Строка с эхом «Этот каталог называется pwd» отказывается предоставить текущий рабочий каталог, как ожидалось. Пожалуйста, помогите мне решить эту проблему, в настоящее время я изучаю BASH SHELL SCRIPTING
Необходимо использовать
echo "This directory is called $(pwd)"
, Что Вы пытаетесь сделать, назван замена команды . Это раньше делалось с помощью обратных галочек (` `
), но в настоящее время рекомендуемый путь использует $()
.
можно найти подробное объяснение на этой странице Wiki.
Получить текущий рабочий каталог как переменная :
echo $PWD
(прописные буквы) или использование команда
pwd
Затем с помощью переменная , строка должна быть:
echo "This directory is called '$PWD'"
Вывод:
This directory is called /home/jacob