Facebook Twitter Instagram
    WiredRevolution.com
    • Home
    • About
    • Contact Us
    • Essential Linux Commands
    • Sitemap
    Facebook Twitter Instagram
    WiredRevolution.com
    bash

    Single versus double quotes in BASH

    RyanBy RyanOctober 15, 2008Updated:October 16, 20081 Comment1 Min Read
    Facebook Twitter Pinterest LinkedIn Reddit WhatsApp Email

    Understanding the difference between double versus single quotes is important when using BASH. Many times you may have seen them being used interchangeably. The basic difference is that variable names will be expanded within double quotes but not within single ones.

    This example shows the normal output with no quotes.

    $ echo $USER
    
    ryan
    

    As you can see the shell will expand the variable.

    In this example we will surround the variable with double quotes.

    $ echo "$USER"
    
    ryan
    

    We see the same result as before.

    This time with single quotes.

    $ echo '$USER'
    
    $USER
    

    The variable name is not expanded.

    Here is another interesting case. The single quotes are inside the double quotes.

    $ echo "'$USER'"
    
    'ryan'
    

    The variable is expanded and the single quotes are retained.

    Here I flip the order with the single quotes on the outside.

    $ echo '"$USER"'
    
    "$USER"
    

    The variable is not expanded but the double quotes are retained.

    Share. Facebook Twitter Pinterest LinkedIn WhatsApp Reddit Email
    Previous ArticleDisplay the first part of a file with head
    Next Article I/O redirection in BASH

    Related Posts

    How to test the syntax of a Python script

    Safely and atomically change a symlink target

    Find the exit status of a previous command in Bash

    Most Commented
    March 12, 2009

    Fix blue tinted video in Ubuntu

    September 10, 2010

    Setup SSH access between VirtualBox Host and Guest VMs

    March 8, 2011

    Install GNOME Shell in Ubuntu 10.10 Maverick

    April 4, 2009

    Setup the PS3 Bluetooth Controller on Ubuntu

    October 22, 2008

    How to correctly use LD_LIBRARY_PATH

    Recent Comments
    • Execute command on linux virtual machine (or server) from windows commandline on Setup SSH access between VirtualBox Host and Guest VMs
    • Solved: How to SSH to a VirtualBox guest externally through a host? - Daily Developer Blog on Setup SSH access between VirtualBox Host and Guest VMs
    • How to SSH to a VirtualBox guest externally through a host? [closed] – Code D3 on Setup SSH access between VirtualBox Host and Guest VMs
    • How to copy and paste from VirtualBox? [duplicate] on Setup SSH access between VirtualBox Host and Guest VMs
    • Jackie Laguna on Fix OpenGL: ChoosePixelFormat SketchUp error in WINE
    © 2025 ThemeSphere. Designed by ThemeSphere.

    Type above and press Enter to search. Press Esc to cancel.