Welcome to Linux Shell Scripting 2022
Remote SSH to a native Linux
Content from day 1,2,3 has been moved to the archive. See link above.
Any question from last session?
- How can I get credits?
- You will need to complete a special assignment to obtain 1 ECTS credit (2 credits if you are very motivated). Please email enrico.glerean@aalto.fi to obtain the special assignment.
- Is it only for Aalto students or others as well?
- For Aalto students: if you have a student number we can register the credit for you, most likely it will look as "Individual Courses in Computer Science"
- For other universities: we write a certificate where it explicitly says that this is equivalent to 1 ECTS, and your supervisor or course coordinator will register it to your system. Please note that not all universities/supervisors might accept this, usually this is fine for Doctoral students, but non-Aalto master students should better confirm with their responsible person.
Day 4
https://aaltoscicomp.github.io/linux-shell/arrays-inputs-here-documents/
-
question
-
I missed the part why the index jumped to [6] instead of [3]?
- It's what Ivan was just saying, that arr is not smart enough so in the first example https://aaltoscicomp.github.io/linux-shell/arrays-inputs-here-documents/#arrays the [6] is interpreted as index 6
- I understand, now. it does not understand "[]" could be another element of the array.
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More β
-
hackMD today has some
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More β
- It's a red panda
- cat burger
-
I think associated arrays are like dictionaries!
-
$ man shuf
bash: man: command not found
- in gitbash for example "man" is not installed. You can google for "man shuf" and get the linux manual page for it
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More β
- in gitbash you can do "βhelp" after the command instead of "man command"
- βhelp was helpful, thanks!
-
when should we use declare for defining arrays?
- Only in case of the associative arrays 'declare -A arr_name' is required. There is also an option to declare array of integers, declare -ia arr_name; otherwise indexed arrays can be defined with arr_name=(item1 item2 β¦) directly ommiting the declaration phase
-
why this does not work: arr[$i]=($RANDOM)
?
- ( ) executes the command in a subshell and returns the exit value⦠not what you want here
- what is usage of executing commands in the subshell?
-
why "" used for ${arr[]}?
- Can you expand the question? Was this used somewhere?
- anywhere you need to refer to array element for instance in the loop or printf
- Usually with echo or printf we pass strings in " " if that is what you mean
- I see it in the for loop as well!
- I see like here
for j in "${!r_num[@]}"...
- I think it should work even without " ", Ivan?
-
Exercise until 12:53
Exercise 2.5 https://aaltoscicomp.github.io/linux-shell/arrays-inputs-here-documents/#exercise-2-5
-
Hey, I need to leave early today, but I would like to thank you guys very much for this joyful study sessions on Linux.
- Thanks and have a nice april's fool!
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More β
-
is [[ -z "$args" ]] equal to [[ -z $args ]] ?:) I still stuck in usage of "" for variables!
- in this particular case that would be no difference, since [[ -z .. ]] check that variable is set, but the value of the variable, andsince variable name can't have special chars, qutes make no difference; consider another example
var='a value with spaces'; [[ $var == 'value' ]] ...
that would bring a syntax error with no quotes.
- There is a difference if $args contains spaces. With quotes it works as if it was a single word.
- Now I remember the case!
-
what does "$@" measn in the cx2 file?
- In any script, $@ is a special variable that contains all the command line options and arguments given as a list separated by spaces, i.e. $@ is '$1 $2 $3 β¦'
- does it include options in for of -a β¦?
- yes, all the options that are typed to the command line, what ever they are
- You can try adding
echo $@
. Lookign and the script, I think it does.
- interestingly the $@ and $opts are equal and both encompass β at the end!
- that means that your command line options/arguments have only option like
-a -v ...
but no arguments like -a -v file1 file2
, in the later case $optswould become '-a -v β file1 file2'; getopt does two things: validates that command line options are only allowed ones and structure them so, that options come first, then β , amd then arguments
-
when I run the cx2 without any changes: cx2 -a -v -d dir name, it complains that directory does not exist even it does, what can be the problem?
- and path to the dir is correct? when run in the current directory, try 'ls -l that_dir' first; just did a demo online, works for me: 'cx2 -a -v -d bin/ test.sh' where both bin/ and test.sh exist
- Can you paste the command you run?
- ./cx2 -a -v -d d1
-
.
-
What would be the best way to ask questions or contact if needed after the course (for example regarding assignment)? Is it ok to email enrico.glerean@aalto.fi?
-
.Thank you for organizing teh course.
-
.Was it stated in the e-mail the deadline for the assignment?
- Thursday 21/April 12:00
- we will repeat the date in the final email to all of you
-
.For how long will the recorded sessions be available in the drive link that was sent? Will they be uploaded to the YT channel? TY.
- At some point they will go to youtube, after editing. So no worries.
-
And the shell history and Q&A from HackMD? will they also be available later?
- Yes, they will stay here, if you scroll up, the previous days are there
- Above there is the link for the archive of hackmd, that will stay "forever". The shell history etc: we can package it and save it on some git repo.
Feedback
You can write here, but you will receive an anonymous form that you can answer.
Always good to suggest improvements so we can make this even better next year!
- Thank you once again for the organisation of the course. I personally like the hybrid method because it allows people from other parts of Finland to attend it. And the diffusion this and the past course had received was great. Thanks a lot!
This is the end of the document, WRITE ABOVE THIS LINE ^^
HackMD can feel slow if more than 100 participants are editing at the same time: If you do not need to write, please switch to "view mode" by clicking the eye icon on top left
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More β