我试图提示用户重复输入一个目录,然后脚本将检查目录是否存在,如果没有继续提示,直到用户输入一个有效的目录。
我的代码:
#!/bin/bash
while :
do
echo "Enter a directory:"
read directory
if [ -f $directory ]
then
cd $directory
break
else
echo "Directory does not exists, please try again."
fi
done
现在的问题是,即使当我输入有效的目录(例如/home/username )时,它仍然在循环而不是
我正在做一个需要批量处理大量图像文件的项目。为了简单起见,我编写了一个脚本,它将创建n目录,并根据用户输入将m文件移动到这些目录中。
我现在的问题是通过shell脚本理解目录遍历。
我已经在上述排序脚本的末尾添加了以下代码片段
dirlist=$(find $1 -mindepth 1 -maxdepth 1 -type d)
for dir in $dirlist
do
cd $dir
echo $dir
ls
done
当我在一个包含两个内部文件夹的Pano2文件夹中运行它时,我总是得到一个错误
./dirTravel: line 9: cd: Pano2/05-15-201
我是一个新手,目前正在学习如何在UNIX中编写脚本。我使用过Vim之类的工具来编写脚本。让我们这样说:
#!/bin/bash
echo -e "Hi, please type the word: \c "
read word
echo "The word you entered is: $word"
echo -e "Can you please enter two words? "
read word1 word2
echo "Here is your input: \"$word1\" \"$word2\&
我正在尝试创建一个脚本,借此我有数字测试文件夹的列表,并希望用户能够在输入文件夹编号后cd到其中之一。
脚本正确地连接了输入,但是在运行脚本时,它实际上没有将cd命令执行到所需的目录吗?
它回显到屏幕上,然后就像是在等待进一步的提示一样?
有人能告诉我我遗漏了什么吗?脚本'chgdir‘如下:
#!/bin/bash
#
# Script to move to test##dir (using input from user for dir number)
echo "Enter test directory number as ## and hit Return"
我在/etc/profile.d/中放置了一个脚本
# default_dba.sh
if groups | grep -qw "dba" ;
then
if [ $USER != "oracle" ]; then
. /u00/scripts/oracle_alias
fi
fi
如果LDAP用户是dba组的成员,则scipt设置别名。这是可行的。LDAP用户启动一个python脚本。作为最后一步,python脚本调用一个新的bash shell
subprocess.call(['/bin/bash', '-i'], s
OS: Ubuntu 14.04
我对shell编程很陌生(我没有时间成为专家,因为我不想经常这样做),但我需要在脚本中做一些准备Rails应用程序部署的事情。我有以下脚本:
#!/bin/bash
cd ~
sudo ls -l
read -p $'Enter version of Ruby you want to use, ex: 2.1.7\n' rubyv
if [ "$rubyv" = '' ]; then
echo 'You did not enter a Ruby version to use, exiting...
我不是Perl用户,所以我只知道最基本的语法,但我从同事那里继承了一些脚本,以便进行数据分析。
具体来说,我无法理解他的perl脚本是如何使用以下方法定位适当的输入/输出目录的:
opendir DIR, "." or die
我看到opendir使用的方式是
opendir DIR, </yourpath> or die
我无法在脚本中找到任何指示要访问哪个目录名的位置,那么什么是“”。语法做什么?我想也许它只是指示打开当前目录,但这大概是
opendir DIR, './' or die
在任何情况下,程序在不访问所需文件的情况下终止,所以我猜这