-1

In a bash file test.sh, I put

#!/bin/bash

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

When I run the script sh test.sh, I receive an error saying
awk: fatal: cannot open file '/home/dir/file' for reading (No such file or directory). How do I make awk to deal with file with whitespaces?
I tried file\ with\ white\ space as well but doesn't work.

wkde
  • 125

1 Answers1

1

Exactly the same as in other contexts, you quote it:

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

This will also prevent the case where you have filenames with glob characters myfile="$dirpath/*"

Ángel
  • 3,589