-1

I'm working in Linux. When I use the terminal, I can open a file like this:

cat filename > /dev/null

I need to create a script that performs this task above. So I created a script named scriptname using nano & chmod +x, and it contains the line of code above.

When I call the script it will specifically look for 'filename,' but what I need is to enter a dynamic filename like scriptname userDefinedFilename. So the bolded part of the code below needs to be dynamically replaceable with user input.

cat filename > /dev/null

Is there a specific name for this kind of scripting within linux? Knowing the name would really help me find these answers through google in the feature.

Support Ukraine
  • 42,271
  • 4
  • 38
  • 63
user3776022
  • 217
  • 3
  • 12
  • "Knowing the name would really help me find these answers through google in the feature".... certainly it would, but guess what... https://www.google.hu/search?q=linux+dynamic+filename – Karoly Horvath Jan 08 '17 at 12:09

1 Answers1

1

If it is just a parameter (the filename) you can read it from command line with $1 How do I parse command line arguments in Bash? You can also read inside your script with read: http://tldp.org/LDP/Bash-Beginners-Guide/html/sect_08_02.html The name is bash scripting or bash programming: http://tldp.org/HOWTO/Bash-Prog-Intro-HOWTO.html If you use a different shell (different from bash) you'll have to learn the peculiarities for this shell.

Community
  • 1
  • 1
fernand0
  • 310
  • 1
  • 10