Say I want to use the name of a file as input, and process it with a pre-made script in a certain directory. How do I do it?
fileName < /folder1/scriptName is this the right format?
You need to pass the name of the file as a parameter to the script
#!/bin/bash # myscript.sh FILENAME=$1 echo "This is the filename:" $FILENAME Then this is how you will call the script
./myscript.sh thisfile.txt This will be the output for the script
This is the filename: thisfile.txt These are some of the tests I executed:
$ vi scriptName.sh #!/bin/bash cat Then executed,
$ ./scriptName < fileName It will print the contents of the file.
This is a very basic example and the input is used only in one place. If you are processing the input in more than one place, which is usually the case when you write a script, then you will have to use the answer given by Fazle.
./path/to/script < file_name.