VIU CSCI USB thumb drive lab exam usage

Table of Contents

1 Question: How do I make an executable file that I can run from the USB drive?

Answer: Create the file with an filename extension of .exe. In the case of a compiled program, you can typically use the -o option of the compiler - for example:

$ cd /media/exam/USBKEY001
$ ... create helloworld.cpp ...
$ g++ -o helloworld.exe helloworld.cpp
$ ./helloworld.exe
hello world
$

In the case of a script, you can create it the way you normally would with a "shebang" line, but make sure the filename has a .exe extension - for example:

$ cd /media/exam/USBKEY001
$ ... create helloworld.sh.exe ...
$ ./helloworld.sh.exe
hello world
$

In this example the first line of the script is:

#!/bin/bash

2 Question: I created an executable called foo (or a.out or …) but I get Permission denied when I try to run it - how can I run it?

Answer: try copying the file to one with a name ending in .exe, or use a compiler option, such as -o for the GNU C and C++ compilers, to generate an output file with such an extension.

$ cd /media/exam/USBKEY001
$ ... create helloworld.cpp ...
$ g++ helloworld.cpp
$ ./a.out
bash: ./a.out: Permission denied
$ cp a.out a.exe
$ ./a.exe
hello world
$

Note: renaming a.out to a.exe above does not work - you must create the file for this to work.

3 Question: I created a script called helloworld.sh (or answer or foo.pl or …) but I get permission denied - how can I run it?

Answer: You can run the file by invoking the required shell or interpreter, typically bash, with the filename as its argument, or you can create the file with an .exe extension, possibly by copying one that does not work. Here is an example of the first solution:

$ cd /media/exam/USBKEY001
$ ... create helloworld.sh ...
$ ./helloworld.sh
bash: ./helloworld.sh: Permission denied
$ bash helloworld.sh
hello world
$

And here is an example of the second:

$ cd /media/exam/USBKEY001
$ ... create helloworld.sh.exe ...
$ ./helloworld.sh.exe
hello world
$

Note that in the second case the first line of the file should contain a standard "shebang" line with the path to the appropriate executable. For example:

#!/bin/bash

Author: Jim Uhl

Created: 2017-11-30 Thu 12:22

Validate