Kunal kishor
Kunal kishor

Reputation: 11

How can i store file name as a variable in shell script

what is wrong with following code?

TEXT=$(<"$(pwd)/data.csv")
IFS=','
cut -d, -f1,2  $TEXT | while read street city ; do
    echo "$street $city"
done

If I am providing the file name directly then it is working

IFS=','
cut -d, -f1,2  data.csv | while read street city ; do
    echo "$street $city"
done

Upvotes: 0

Views: 534

Answers (2)

Kevin C
Kevin C

Reputation: 5770

How can i store file name as a variable in shell script

#!/bin/bash

FILEPATH="$(pwd)/something"
echo $FILEPATH

Upvotes: 1

flopez
flopez

Reputation: 610

Why not simply execute this code:

while read street city ; do
  echo "$street $city"
done < data.csv

Upvotes: 0

Related Questions