我正在尝试将shell脚本中的目录更改为命令行参数给出的目录。
#!/bin/bash
chmod 755 findfn.sh
dir=$1
while [ -d "${dir}" ]
do
cd $HOME/"$1"
done
我看了很多其他帖子并尝试过:
cd "dir"
cd ~/"$1"
cd source "$1"
#!bin/bash
chmod 755
更改为chmod 700
等我哪里错了?
EDIT 刚试过这个
alias dirc="cd /home/$1"
echo $PWD
但它仍然没有改变目录,它只是不断打印出来 “/家”
答案 0 :(得分:0)
$ cat a.sh
#!/bin/bash
dir=$1
while [ -d "${dir}" ] #it will check if the argument directory is present where script is executed.
do
cd $HOME/"$1"
done
假设/tmp
包含上述脚本为a.sh
,
并且存在/tmp/abc
和/home/abc
,
然后您必须运行如下脚本:
$. a.sh abc
,它将转到/home/abc