-1
#!/bin/bash
while read -r line; do
mkdir "UNIX/$line"
done < usernames.lnk

以下に示すスクリプトを実行すると、このエラーが発生します。スペルミスがないかチェックしましたが、スクリプトとユーザー名ファイルの両方が同じフォルダーにありますが、ファイルを検出できません。

/home/user/Documents/New/taskscript.sh: line 4: usernames.lnk: No such file or directory
4

3 に答える 3

4

スクリプトは、現在のフォルダー (つまり、ファイルが保存されているフォルダーではなく、スクリプトを開始したフォルダー) でファイルを探します。

代わりに次のコードを試してください。

#!/bin/bash

# Determine folder in which this script is stored
BASE=$( cd $( dirname "$0" ) > /dev/null ; pwd )

while read -r line; do
mkdir "UNIX/$line"
done < "$BASE/usernames.lnk"
于 2013-01-10T16:22:10.463 に答える
1

The usernames file needs to be in the current directory when you run the script - having it in the same directory as the script will only work when you call the script from that directory.

You should use a full path in the last line if you want to be able to call that script from anywhere.

于 2013-01-10T16:20:55.060 に答える
0

使ってみてください

./usernames.lnk

それ以外の

usernames.lnk
于 2013-01-10T16:19:40.823 に答える