Taking file input

How do i take file as input in a bash script, Do i need to give the full path or just the name?

When you write $1 in the script. It will act as a command line argument and then you can pass the arguments while running your bash script

I tried this. Do i pass the path to the file version as the argument or just the file name?

For example -

bash script (samp.sh)-
cat $1 | grep ‘xyz’

When you run the script - ./samp.sh samp.txt

then our command will be like this cat samp.txt |grep 'xyz'

1 Like