Results 1 to 5 of 5

Thread: bash multiline command

  1. #1
    Join Date
    Jun 2011
    Location
    Netherlands
    Beans
    181
    Distro
    Ubuntu 12.04 Precise Pangolin

    bash multiline command

    Hello,

    How can I execute a command that involves multiple lines, like a for loop? Just like:

    Code:
    for i in foo bar 
    do
    echo $i;
    done;
    Appending a backslash at the end of each line does not work, because a for loop seems to require the parts on separate lines.
    Vim - Comfortable text editing and coding
    vim-autoformat - a code-formatting plugin for vim supporting various languages - https://github.com/Chiel92/vim-autoformat
    Vimperator - Fast browsing using keyboard only

  2. #2
    Join Date
    Mar 2007
    Location
    Turkey
    Beans
    1,575

    Re: bash multiline command

    Why not put them together in a .sh file?

  3. #3
    Join Date
    Jun 2011
    Location
    Netherlands
    Beans
    181
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: bash multiline command

    Yeah, that's a workaround, but I thought it'd be easy and nice if I could do it directly in the terminal. That saves a file creation, chown and opening and closing your editor.
    Vim - Comfortable text editing and coding
    vim-autoformat - a code-formatting plugin for vim supporting various languages - https://github.com/Chiel92/vim-autoformat
    Vimperator - Fast browsing using keyboard only

  4. #4
    Join Date
    Jul 2007
    Location
    Poland
    Beans
    4,243
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: bash multiline command

    Code:
    for i in foo bar; do echo $i; done
    
    while read line; do echo $line; done < input.file
    
    if condition; then echo TRUE; else echo FALSE; fi
    also when you type in incomplete command you will get > prompt to continue
    so you can write:
    Code:
    $ while true
    > do
    > echo stuff
    > sleep 1
    > done
    stuff
    stuff
    stuff
    done ending the while loop automatically runs it
    Last edited by Vaphell; November 3rd, 2011 at 10:42 PM.

  5. #5
    Join Date
    Jun 2011
    Location
    Netherlands
    Beans
    181
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: bash multiline command

    Quote Originally Posted by Vaphell View Post
    Code:
    for i in foo bar; do echo $i; done
    
    while read line; do echo $line; done < input.file
    
    if condition; then echo TRUE; else echo FALSE; fi
    also when you type in incomplete command you will get > prompt to continue
    so you can write:
    Code:
    $ while true
    > do
    > echo stuff
    > sleep 1
    > done
    stuff
    stuff
    stuff
    done ending the while loop automatically runs it
    Ahh, thanks!
    I used to put slashes at the end of each line.
    Vim - Comfortable text editing and coding
    vim-autoformat - a code-formatting plugin for vim supporting various languages - https://github.com/Chiel92/vim-autoformat
    Vimperator - Fast browsing using keyboard only

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •