Question: I have a task where I'm given an input of the format:

```
4
A CS 22 M
B ECE 23 M
C CS 23 F
D CS 22 F

```

as the user input from the command line. From this, we have to perform tasks like determine the number of male and female students, determine which department has the most students, etc. I have done this using awk with the input as a file. Is there any way to do this with a user input instead of a file?

Example of a command I used for a file (where the content in the file is in the same format):

```
numberofmales=$(awk -F ' ' '{print $4}' file.txt | grep M | wc -l)                     #list number of males

```

Answer: 
Firstly, what you have isn't a regular expression. Expansions done by the shell involving `*` are called [Filename Expansions](https://www.gnu.org/software/bash/manual/html_node/Filename-Expansion.html), also known as "glob" expansion.

Also you are *not* using an array to hold your contents, but using a scalar type. When you assign the glob expression to a variable is it assigned "literally" and when you do a unquoted expansion with `echo`, the shell expands the variable first and then expands the glob to its resulting files. But remember that variables by default are of scalar type, they can contain only one value. For more than one value, you need arrays.

```sh
inputDir=/home/user/TestDir
files=( "$inputDir"/*txt)
printf '%s\n' "${files[@]}"

```

The list of elements is accessed with `"${files[@]}"` (the double-quotes are important here), and individual elements accessed as `"${files[0]}"`. The things with arrays though, you cease to be POSIX compliant as they are supported in those shells.

Also don't use uppercase letters for variable names in user scripts. The uppercase variable names have special meaning and are reserved for use by the shell only.
Your `files` variable is a string, not an array.

If you want files to be an array you have to write

```sh
#!/bin/bash
INPUT_DIR='/home/user/TestDir'
files=( "$INPUT_DIR/"*txt )

```