How to write a bash script

Video is ready, Click Here to View ×


On Mac or Linux, how to make a script/pipeline on the command-line in bash.
LINK TO omgenomics.com/bash-script
Code:
#!/usr/bin/env bash
NAME=${1?Error: no name given}
NAME2=${2:-friend}
echo “HELLO! $NAME and $NAME2”

Run as:
./myscript Tom
or
./myscript Tom Jerry


13 thoughts on “How to write a bash script”

  • terry acer

    November 9, 2018 at 12:35 am

    You¨re swedish arent ya?

    Reply
  • kmartTheMan

    November 9, 2018 at 12:35 am

    This was extremely helpful in helping me get started on a school assignment, thank you so much

    Reply
  • Raja sekhar

    November 9, 2018 at 12:35 am

    Hi…do we need to use .sh extension on every script or not

    Reply
  • Mosio Masoud

    November 9, 2018 at 12:35 am

    Great 👍🏻

    Reply
  • Mario Parada

    November 9, 2018 at 12:35 am

    Quick question, I am fairly new to shell scripting,
    I am creating a start up script for my oracle DB.
    Once I have loged in to SQLPlus, I prompt user to input password.
    Once the password is given, I connect to SQLPlus, but the script does not run anymore, so I am left on SQLPlus, waiting for me to execute SQL commands.
    I have written the commands I want the script to write, but I am unable to do so.
    #!/bin/bash
    sqlplus sys as sysdba
    stty -echo
    read -p "Password: " pass
    stty echo
    printf 'n'
    sqlplus -S system/manager <<EOF
    STARTUP
    EXIT
    EOF
    echo DB instance Started

    Reply
  • Tugba Akan

    November 9, 2018 at 12:35 am

    It should be 'Hello world', not 'Hello!'

    Reply
  • Aaron Wilson

    November 9, 2018 at 12:35 am

    thanks for the video. It's very helpful cos I can't make sense of things on paper and you gave a great example to get started with.

    Reply
  • Jayashanker

    November 9, 2018 at 12:35 am

    Totally made me worth watching… Good one.

    Reply
  • Agrim IT Education

    November 9, 2018 at 12:35 am

    very nice video…

    Reply
  • Ian

    November 9, 2018 at 12:35 am

    What a helpful video. Thanks a lot! Nice to see more women in STEM.

    Reply
  • James Lloyd

    November 9, 2018 at 12:35 am

    Very helpful video. I have started to do more in bash and less in Python recently but variable inputs is something I have not read up on yet, and now I don't need to thanks to this! Saving me some horrid hard-coded shell scripts!

    Reply
  • Hiram Coria Rodriguez

    November 9, 2018 at 12:35 am

    Hi, i like your video. Would you mind make a video dealing with FASTA texts?

    I excuse for my english, it´s not my first language.

    Reply
  • Shaojun Xie

    November 9, 2018 at 12:35 am

    Hi Maria,
    It seemed that you use Python, Perl, R and Bash in your work. Is it possible you can talk about how you choose a language when you're trying to solve a problem?
    Best,
    Shaojun

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

*
*