AaltoSciComp
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Owners
        • Signed-in users
        • Everyone
        Owners Signed-in users Everyone
      • Write
        • Owners
        • Signed-in users
        • Everyone
        Owners Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
      • Invitee
    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Engagement control
    • Transfer ownership
    • Delete this note
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Sharing URL Help
Menu
Options
Versions and GitHub Sync Engagement control Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Owners
  • Owners
  • Signed-in users
  • Everyone
Owners Signed-in users Everyone
Write
Owners
  • Owners
  • Signed-in users
  • Everyone
Owners Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
Invitee
Publish Note

Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

Your note will be visible on your profile and discoverable by anyone.
Your note is now live.
This note is visible on your profile and discoverable online.
Everyone on the web can find and read all notes of this public team.
See published notes
Unpublish note
Please check the box to agree to the Community Guidelines.
View profile
Engagement control
Commenting
Permission
Disabled Forbidden Owners Signed-in users Everyone
Enable
Permission
  • Forbidden
  • Owners
  • Signed-in users
  • Everyone
Suggest edit
Permission
Disabled Forbidden Owners Signed-in users Everyone
Enable
Permission
  • Forbidden
  • Owners
  • Signed-in users
Emoji Reply
Enable
Import from Dropbox Google Drive Gist Clipboard
   owned this note    owned this note      
Published Linked with GitHub
Subscribed
  • Any changes
    Be notified of any changes
  • Mention me
    Be notified of mention me
  • Unsubscribe
Subscribe
# 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: :::

Import from clipboard

Paste your markdown or webpage here...

Advanced permission required

Your current role can only read. Ask the system administrator to acquire write and comment permission.

This team is disabled

Sorry, this team is disabled. You can't edit this note.

This note is locked

Sorry, only owner can edit this note.

Reach the limit

Sorry, you've reached the max length this note can be.
Please reduce the content or divide it to more notes, thank you!

Import from Gist

Import from Snippet

or

Export to Snippet

Are you sure?

Do you really want to delete this note?
All users will lose their connection.

Create a note from template

Create a note from template

Oops...
This template has been removed or transferred.
Upgrade
All
  • All
  • Team
No template.

Create a template

Upgrade

Delete template

Do you really want to delete this template?
Turn this template into a regular note and keep its content, versions, and comments.

This page need refresh

You have an incompatible client version.
Refresh to update.
New version available!
See releases notes here
Refresh to enjoy new features.
Your user state has changed.
Refresh to load new user state.

Sign in

Forgot password

or

By clicking below, you agree to our terms of service.

Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
Wallet ( )
Connect another wallet

New to HackMD? Sign up

Help

  • English
  • 中文
  • Français
  • Deutsch
  • 日本語
  • Español
  • Català
  • Ελληνικά
  • Português
  • italiano
  • Türkçe
  • Русский
  • Nederlands
  • hrvatski jezik
  • język polski
  • Українська
  • हिन्दी
  • svenska
  • Esperanto
  • dansk

Documents

Help & Tutorial

How to use Book mode

Slide Example

API Docs

Edit in VSCode

Install browser extension

Contacts

Feedback

Discord

Send us email

Resources

Releases

Pricing

Blog

Policy

Terms

Privacy

Cheatsheet

Syntax Example Reference
# Header Header 基本排版
- Unordered List
  • Unordered List
1. Ordered List
  1. Ordered List
- [ ] Todo List
  • Todo List
> Blockquote
Blockquote
**Bold font** Bold font
*Italics font* Italics font
~~Strikethrough~~ Strikethrough
19^th^ 19th
H~2~O H2O
++Inserted text++ Inserted text
==Marked text== Marked text
[link text](https:// "title") Link
![image alt](https:// "title") Image
`Code` Code 在筆記中貼入程式碼
```javascript
var i = 0;
```
var i = 0;
:smile: :smile: Emoji list
{%youtube youtube_id %} Externals
$L^aT_eX$ LaTeX
:::info
This is a alert area.
:::

This is a alert area.

Versions and GitHub Sync
Get Full History Access

  • Edit version name
  • Delete

revision author avatar     named on  

More Less

Note content is identical to the latest version.
Compare
    Choose a version
    No search result
    Version not found
Sign in to link this note to GitHub
Learn more
This note is not linked with GitHub
 

Feedback

Submission failed, please try again

Thanks for your support.

On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

Please give us some advice and help us improve HackMD.

 

Thanks for your feedback

Remove version name

Do you want to remove this version name and description?

Transfer ownership

Transfer to
    Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

      Link with GitHub

      Please authorize HackMD on GitHub
      • Please sign in to GitHub and install the HackMD app on your GitHub repo.
      • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
      Learn more  Sign in to GitHub

      Push the note to GitHub Push to GitHub Pull a file from GitHub

        Authorize again
       

      Choose which file to push to

      Select repo
      Refresh Authorize more repos
      Select branch
      Select file
      Select branch
      Choose version(s) to push
      • Save a new version and push
      • Choose from existing versions
      Include title and tags
      Available push count

      Pull from GitHub

       
      File from GitHub
      File from HackMD

      GitHub Link Settings

      File linked

      Linked by
      File path
      Last synced branch
      Available push count

      Danger Zone

      Unlink
      You will no longer receive notification when GitHub file changes after unlink.

      Syncing

      Push failed

      Push successfully