cpはスクリプトでは機能しませんが、コマンドラインでは機能します。

cpはスクリプトでは機能しませんが、コマンドラインでは機能します。

コマンドラインで番号をスキャンし、パスを提供するディレクトリファイルからその番号を検索し、上記の番号に対応するDVDをそのパスにコピーする簡単なプロセスを自動化するスクリプトがあります。 cp コマンドは引き続き失敗します。スクリプトでcpが機能しない他の投稿を見たことがありますが、すべてファイル名の周りに引用符が付いているようです。私はこれが私の問題だとは思わない。

結果がより明確になることを願って、いくつかのコメントを追加しました。

\#!/bin/bash
\# accepts a single command line parameter:  six-digit DVD number, ex. 987110
\# the empty echo lines are just whitespace for readability**

clear

file=/public/TAPES/batch1/Shipment_1_catalog.txt.dvd

echo
echo DVD number is       $1

echo
echo catalogfile is      $file

>\# this grep instruction greps $1 out of $file
>\# output from this is 'XXXXXX file-path-to-copy-dvd-contents-to'
>\# qwk puts the file-path... into $pth

pth=`grep $1 $file | awk ' { print $2 } '`

echo

echo destination path is $pth

echo

mount /dev/sr0 /media     # appears to work

cp -p -r /media/\* $pth   # this always fails - see error text below.

echo

umount /dev/sr0 && eject  # this does work

コピーコマンドを除いて、すべてがうまく機能します。次のエラー出力が生成されます。

DVD番号は987110です。

catalogfile is /public/TAPES/batch1/Shipment_1_catalog.txt.dvd

destination path is > /proj/T_010/gdm/SAM/BRA/3D/Santos_ESP_3D_BDEP_2010/dvd/legacy/987110_Line_Section_Various_Vintages-Post_Stack_Migration_DVD_14_of_41

mount: block device /dev/sr0 is write-protected, mounting read-only
cp: cannot stat `/media/*': No such file or directory

このスクリプトの権限は755です。私は「./cpy.sh」と「bash cpy.sh」を試してみましたが、両方とも同じ結果を得ました。

ベストアンサー1

UNIXシステムでは、ワイルドカード文字はシェルで処理されます。*次のコマンドのエスケープ文字は、名前cpが指定されているように見えるが存在しない可能性があるファイルを渡します。/media/*

cp -p -r /media/\* $pth

対照的に、Windowsではコマンドプロセッサではなくコマンド*によって処理されます。copy

ルートのみファイルの所有権を変更できます。そうしないと、システム内のすべてのユーザーが他のユーザーのファイルを取得できます。cp: failed to preserve ownership ...予想通りそうです。

おすすめ記事