ファイルパスとユーザーが入力した文字列を区別する方法

ファイルパスとユーザーが入力した文字列を区別する方法

私が探しているもの - 適応方法 - ユーザー入力ファイルの場所と文字列(1行に1つの文字列または文字列のリストである可能性があります)を自動的に区別しますか?

#!/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

2番目の場合:コピーするときに名前を貼り付けます。

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

おすすめ記事