태그 보관물: file-location

file-location

쉘 스크립트를 사용하여 스크립트가 다른 위치에있는 동안 위치에있는 파일에 액세스해야합니다 내 file_1에서

위치에 파일을 배치했습니다

/tmp/parent_dir/child_dir/file_1

스크립트는 위치에 배치됩니다

/usr/local/bin/file_load/load_data

이 위치 ( /usr/local/bin/file_load/load_data) 에서 스크립트 내 file_1에서 다른 위치 ( /tmp/parent_dir/child_dir/file_1) 에 있는 파일 ( )에 어떻게 액세스 할 수 있습니까?



답변

쉘 스크립트가 명령 행에서 파일의 경로를 수신하도록 하시겠습니까? 이와 같은 것이 도움이 될 것입니다.

#!/bin/bash
file=$1
cat $file

그런 다음 다음과 같이 스크립트를 호출 할 수 있습니다.

 /usr/local/bin/file_load/load_data /tmp/parent_dir/child_dir/file_1

파일을 출력합니다.


답변