Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download

terminal exercises

Views: 2497
1
Here are some links on this topic:
2
3
https://www.pythonforbeginners.com/system/python-sys-argv
4
5
https://www.tutorialspoint.com/python/python_command_line_arguments.htm
6
7
Basically command line arguments are strings after the program name in a command line call to an executable
8
9
For instance:
10
11
$ echo "rinderpest kills cattle"
12
13
makes a call to the executable called 'echo' which just prints out the arguments it receives. In this case we pass in one command line argument, namely the string "rinderpest kills cattle".
14
15
Some executables take many arguments. For example:
16
17
$ touch a lonely broccoli
18
19
makes a call to the executable called 'touch' which can be used to create files. The command should have created three files: a, lonely, and broccoli.
20
21
You can see them like this:
22
23
$ ls
24
25
26
(This will print the files in the current directory)
27
28
Another kind of command line argument is to provide "options" to a command.
29
30
For instance
31
32
$ ls -ltrc
33
34
This calls the ls command with three options: l,t,r, and c. You can see what each of these options does by looking at the documentation:
35
36
$ man ls
37
38
39
We will not make use of it, but there is a python module which automatically parses command line input into, for example, files and options. It is described in the second link given above.
40
41
Now play around with the script cmd_arg.py
42
43
Look at the code.
44
45
Try
46
47
$ ./cmd_arg.py
48
49
$ ./cmd_arg.py hwy 2 heck
50
51
52
53