epita-2023
      • 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
    • Invite by email
      Invitee

      This note has no invitees

    • 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
    • Note Insights
    • 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 Versions and GitHub Sync Note Insights Sharing URL Help
Menu
Options
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
  • Invite by email
    Invitee

    This note has no invitees

  • 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
    --- tags: epita, piscine --- # 42sh Wiki # SCL structure - **==Shell introduction==** - **==Quoting==** - Escape Character (Backslash) `\` - Single-Quotes `'` - Double-Quotes `"` - **==Token Recognition==** - Alias Substitution - **==Reserved Words==** - **==Parameters and Variables==** - Positional Parameters - Special Parameters - Shell Variables - **==Word Expansions==** - Tilde Expansion - Parameter Expansion - Command Substitution - Arithmetic Expansion - Field Splitting - Pathname Expansion - Quote Removal - **==Redirection==** - Redirecting Input - Redirecting Output - Appending Redirected Output - Here-Document - Duplicating an Output File Descriptor - Open File Descriptors for Reading and Writing - **==Exit Status and Errors==** - Consequences of Shell Errors - Exit Status for Commands - **==Shell Commands==** - Simple Commands - Pipelines - Lists - Compound Commands - Function Definition Command - **==Shell Grammar==** - Shell Grammar Lexical Conventions - Shell Grammar Rules - **==Signals and Error Handling==** - **==Shell Execution Environment==** - **==Pattern Matching Notation==** - Patterns Matching a Single Character - Patterns Matching Multiple Characters - Patterns Used for Filename Expansion - **==Special Built-In Utilities==** # Tips ## 1) Utilities - `tree -I 'venv|build'`: display all directories execpt `venv` and `build`. - `alias ccg="gcc -Wall -Wextra -Werror -pedantic -std=c99 -g -fsanitize=address -o out"` ## 2) Shell ### <ins>A) To check if command is POSIX-compliant</ins> - run `bash --posix` in terminal. - run your `command` ## 3) Cmake ### <ins>A) General</ins> - Add macro to target (ex: `_XOPEN_SOURCE >= 500`) - [Conférences 42sh 2019 - Build systems => Timeline 2:16:56](https://youtu.be/jp1l4mg3NN0?t=8216) - Include directories to target (ex: `gcc -Isrc`) - [Conférences 42sh 2019 - Build systems => Timeline 2:17:39](https://youtu.be/jp1l4mg3NN0?t=8259) ### <ins>B) Run Pytest</ins> - First time: - Download `conftest.py` (Renamed if needed) and move it to test folder. (not needed as pierre did it for us) - Run `python -m venv venv` to create env. ( in root of dir) - To activate env, run `source venv/bin/activate` - Run `pip install pytest pyyaml` - Run `pip install cmake-format` ==(`cmake-format -i CMakeLists.txt`)== - To run tests, type `pytest` - Tests are written in a `.yaml` file (see `conftest.py` for syntax). - To deactivate env, run `deactivate` - Other: - To activate env, run `source venv/bin/activate` - To run tests, type `pytest` - To deactivate env, run `deactivate` ### <ins>C) Run criterion tests</ins> > To run criterion testsuite: `ctest --verbose` or `make check` (if implemented). - Suppose the following architecture: ``` ├── CMakeLists.txt (1) ├── src │   ├── CMakeLists.txt (2) │   ├── lexer │   │   ├── CMakeLists.txt (3) │   │   ├── lexer.c │   │   ├── lexer.h │   │   ├── token.c │   │   └── token.h └── tests └── utests ├── CMakeLists.txt (4) ├── lexer │   └── lexer_1.c ``` - [x] In `CMakeLists.txt (1)`, make sure to have: - `add_subdirectory(src/lexer)` - [x] In `CMakeLists.txt (2)`, make sure to have: - `target_link_libraries(42sh PRIVATE ${READLINE_LIB} common_options lexer)` - [x] In `CMakeLists.txt (3)`, make sure to have: ``` add_library(lexer STATIC <--- THIS lexer.c lexer.h token.c token.h ) target_include_directories(lexer PUBLIC .) <--- THIS target_link_libraries(lexer PRIVATE common_options) <--- THIS ``` - [x] In `CMakeLists.txt (4)`, make sure to have: ``` find_library(CRITERION_LIB criterion) add_executable(test_criterion utests_1.c lexer/lexer_1.c) ^ `--- THIS target_link_libraries(test_criterion PRIVATE ${CRITERION_LIB} common_options lexer <-- THIS ) ``` - [x] In `lexer/lexer_1.c`, only need to include `#include "token.h"` ## 4) Git ### A) <ins>`.git/config`</ins> ```c= [core] pager = less -S [alias] tree = log --graph --decorate --pretty=oneline --abbrev-commit ``` - `git tree`: view commit in tree-like view. - `git config --global pull.rebase true`: Enable pull rebase. ### B) branching - `git branch`: Display all existing branches. - `git checkout <branch>`: switch branch - `git checkout -b <branch>`: create branch + switch branch - `git push --set-upstream origin <branch>`: Tells git to push to `<branch>` and not master. ### C) Merge - `git checkout master` - `git pull` - `git merge <name_branch>` ## 5) Debugging - In your file test, replace `Test(....)` by `int main(void)` - Run `make debug`, an executable named `utest_criterion` will be created. - Run `gdb utest_criterion`. - ==**ALWAYS `make clean` + `rm utest_criterion`**== - because the `utest_criterion` at the root is a copy from the one in test. Thus `make clean` won't see it. ### Valgrind - At root, `mkdir build/` - `cd build` - `cmake .. -DCMAKE_BUILD_TYPE=Release` (This should run version without fsanitize=address) ### fsanitize=address - At root, `mkdir debug/` - `cd debug` - `cmake .. -DCMAKE_BUILD_TYPE=Debug` (This should run version with fsanitize=address) ## 6) Static library linking - Use `-Wl,--start-group` and `-Wl,--end-group` to stop worrying about libraries ordering. ```C target_link_libraries( utest_criterion PRIVATE ${CRITERION_LIB} common_options "-Wl,--start-group" ast execution option_parser parser lexer data-structure utils "-Wl,--end-group") ``` ## 7) Doxygen (manpage) - if you want to have acces to manpage from root, use the command : `groff -man -Tascii doc/42sh.man | less` - Updates can and MUST be done, it can be manipulated like a .txt document in vim/emacs. # Miscellaneous - [Shell architecture (made by ex-ACU)](https://shell.multun.net/index.html) - [Check if script is posix compliant (use !/bin/sh)](https://www.shellcheck.net/) - [Example to clarify interpretation and syntax of shell grammar](https://lists.gnu.org/archive/html/help-bash/2015-07/msg00022.html) - [Layman explication of `Token Recogntion` && `Shell Grammar` sections](https://docs.google.com/document/d/14JO-CZBlcv3WQFh1998gGwD_XOz5kyhyAiqKGSJlFJI/edit) - [Variables en shell Bash](http://www.epons.org/shell-bash-variables.php) - [bash-cheatsheet](https://devhints.io/bash) - [bash: all about redirections](https://catonmat.net/bash-one-liners-explained-part-three) # Conferences - [Shell Grammar conference](https://web.microsoftstream.com/video/aa398132-009f-4bdf-a5a6-8afbb4a71b55) - [Tests UFOs did it: learning about the test pyramid (python too)](https://web.microsoftstream.com/video/77e9f560-9058-40a4-8b16-37ede92fc386) - [Python & Testsuite fonctionnelle](https://www.youtube.com/watch?v=1CoFy6eM7_I) - [Gaby conf achitecture shell](https://www.youtube.com/watch?v=oIFRiwFRSRY)

    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