owned this note
owned this note
Published
Linked with GitHub
# Welcome to Linux Shell Scripting 2022
###### tags: `Linux Shell Scripting`
:::info
This is a hybrid course.
- Course page: https://scicomp.aalto.fi/training/scip/linux-shell-basics/
- This document: https://hackmd.io/@AaltoSciComp/LinuxShellScripting2022
- Archive of this document: https://hackmd.io/@AaltoSciComp/ShellScriptingArchive2022
- Learning materials: https://aaltoscicomp.github.io/linux-shell/
- Demospace: https://users.aalto.fi/~degtyai1/shell/
- Dates: 21, 25, 28 March & 1 APril, 11:50-15:00 EET (Finnish time)
- Zoom room: SENT VIA EMAIL
- On-campus room: Otakaari 1, U135a U7 PWC
- Installation pre-requisites
- Linux/Mac: you already have a bash terminal
- Windows: we recommend https://gitforwindows.org/ (Windows PowerShell is not bash compatible).
- Alternatively, if you have access to a university linux server, you do not need to install anything, you can just open powershell and run something like `ssh username@machine.uni.fi`
- Presemo quizzes: https://presemo.aalto.fi/shellscripting
- Please note that we will record the zoom: do not switch your camera or microphone unless you intend to.
- Command history https://users.aalto.fi/~degtyai1/shell/
:::
:::info
Remote SSH to a native Linux
- Aalto https://scicomp.aalto.fi/aalto/remoteaccess/
- HY https://wiki.helsinki.fi/display/it4sci/Remote+access+to+University+resources
- TUNI https://www.tuni.fi/it-services/handbook/2724/3229
- OULU: https://www.oulu.fi/th/node/212293
:::
---
**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
## Arrays, input, Here Documents
https://aaltoscicomp.github.io/linux-shell/arrays-inputs-here-documents/
- question
- answer
- 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. :+1:
- hackMD today has some :cat:
- 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:+1:
- 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?
- See for example the example at https://dev.to/rpalo/bash-brackets-quick-reference-4eh6
- 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!:+1:
- 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
:::info
# Exercise till xx:27
https://aaltoscicomp.github.io/linux-shell/arrays-inputs-here-documents/#exercise-2-6
:::
- .
- 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?
- Check https://scicomp.aalto.fi/help/garage/ for our daily help session
- You can always email enrico but the best address is scip@aalto.fi (it opens a ticket that many people read and can help you with)
- Ivan email is: ivan.degtyarenko@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
- Thank 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!
---
:::danger
**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 :eye:
:::