![파일 경로와 사용자가 입력한 문자열을 구별하는 방법](https://linux55.com/image/156941/%ED%8C%8C%EC%9D%BC%20%EA%B2%BD%EB%A1%9C%EC%99%80%20%EC%82%AC%EC%9A%A9%EC%9E%90%EA%B0%80%20%EC%9E%85%EB%A0%A5%ED%95%9C%20%EB%AC%B8%EC%9E%90%EC%97%B4%EC%9D%84%20%EA%B5%AC%EB%B3%84%ED%95%98%EB%8A%94%20%EB%B0%A9%EB%B2%95.png)
내가 찾고 있는 것 - 적응 방법 - 사용자 입력 파일 위치와 문자열(한 줄에 하나의 문자열 또는 문자열 목록일 수 있음)을 자동으로 구별합니까?
#!/bin/bash
fun1(){
arrDomains=()
while read domain
do
arrDomains+=($domain)
done
for i in ${arrDomains[@]}
do
echo $i
done > $file_path
return
}
fun2(){
echo "File path is $file_path"
}
read -p "specify the file path or paste domain list" file_path
###### If I specify the file path it should call function - fun2
###### If I copy paste domain list it should call funtions fun1 & fun2
예 - 첫 번째 시나리오: 파일 위치를 입력할 때
specify the file path or paste domain list
/tmp/filelist
두 번째 경우: 복사할 때 이름을 붙여넣습니다.
specify the file path or paste domain list
name1.w.corp
name2
name3.bz.co
...
...
답변1
이 방법으로 도메인 목록을 붙여넣을 수는 없지만 입력이 파일인지 확인할 수는 있습니다.
read -p "specify the file path or paste domain list" file_path
if [[ -f "$file_path" ]]; then
fun2
else
fun1
fun2
fi