![]() |
|
Passing the file name as a command-line argument - نسخة قابلة للطباعة +- Forums (http://ftth.kozow.com) +-- المنتدى: قسم الشرينج والـ IP (http://ftth.kozow.com/forumdisplay.php?fid=5) +--- المنتدى: شروحات و مشاكل الـ VPS و LINUX (http://ftth.kozow.com/forumdisplay.php?fid=7) +--- الموضوع: Passing the file name as a command-line argument (/showthread.php?tid=11) |
Passing the file name as a command-line argument - ftth - 11-04-2025 How to run the script:
bash
كود: ./your_script.sh /path/to/input_file.txt[b]Inside [/b]
كود: your_script.sh[b]:[/b]
You would use the variable
كود: $1 to refer to the file path.
bash
كود: #!/bin/bashRedirecting the file content to standard input
The script reads directly from its standard input (stdin), which the shell connects to the file's content using the
كود: < operator.
[b]How to run the script:[/b]
bash
كود: ./your_script.sh < /path/to/input_file.txt[b]Inside [/b]
كود: your_script.sh[b]:[/b]
The script uses commands that read from stdin, such as
كود: read,
كود: cat,
كود: grep,
كود: tr, etc.
bash
كود: #!/bin/bash3. Using custom argument parsing (for
كود: input_file=)
If you want to use the specific
كود: input_file= format as in your example, you need to parse the arguments manually within your script.
[b]How to run the script:[/b]
bash
كود: ./your_script.sh input_file=/path/to/file.txt[b]Inside [/b]
كود: your_script.sh[b]:[/b]
bash
كود: #!/bin/bash |