awkでスペースを含むファイル名を入力する方法

awkでスペースを含むファイル名を入力する方法

test.sh私が入れたbashファイルに

#!/bin/bash

dirpath="/home/dir"
myfile="$dirpath/file with white space"  
awk '{print "firstcolumn"$1":"$4,$2}' ${myfile}.bim >file2

スクリプトを実行するとsh test.shエラーメッセージが表示されます
awk: fatal: cannot open file '/home/dir/file' for reading (No such file or directory)。空白のファイルを処理するには、awkをどのように取得しますか?
私もfile \ with \ white \ spaceを試しましたが、うまくいきません。

ベストアンサー1

引用した他の文脈とまったく同じです。

awk '{print "firstcolumn"$1":"$4,$2}' "${myfile}.bim" >file2

これにより、グローバル文字を含むファイル名も防止されます。myfile="$dirpath/*"

おすすめ記事