0

Let's assume I have a bash script example.sh. Running the script requires the argument which is the list of the directories. The the script works like this:

./example.sh "/dir/location/281/rest-of-the-location"  "/dir/location/287/rest-of-the-location"  "/dir/location/37/rest-of-the-location"  "/dir/location/3007/rest-of-the-location"

All the list of the directories are saved in a file called file.txt. Is there a simple way to run the script instead putting the directories in the second quote like the above?

All the directories are saved in a file called file.txt

 file.txt
 /dir/location/281/rest-of-the-location
 /dir/location/37/rest-of-the-location
 /dir/location/3007/rest-of-the-location
 /dir/location/3127/rest-of-the-location
/dir/location/37/rest-of-the-location
/dir/location/372/rest-of-the-location
/dir/location/137/rest-of-the-location
Numerical Person
  • 147
  • 1
  • 1
  • 7

1 Answers1

2

Use xargs:

xargs ./example.sh < file.txt

If example.sh interacts with the user, you may need to add the -o option to xargs, or with GNU xargs use xargs -a file.txt ./example.sh

glenn jackman
  • 238,783
  • 38
  • 220
  • 352
  • `xargs -a file.txt ./example.sh ` this one worked. Thanks. `xargs ./example.sh < file.txt` this is not showing anything If I use `o` option, it says `xargs: invalid option -- 'o'` – Numerical Person May 17 '21 at 14:23