Results 1 to 4 of 4

Thread: BASH Shell Functions

  1. #1
    Join Date
    Nov 2007
    Location
    UK
    Beans
    192
    Distro
    Xubuntu 16.04 Xenial Xerus

    BASH Shell Functions

    Hi,

    Is it possible to create a BASH shell function that accepts arguments at the prompt? I want to create a function that allows the user to carry out a long complex command string by entering a single command, but the command string takes an argument that may change depending on user preference.

    For example:
    I've created the function bg which will carry out gconftool-2 --type string --set /apps/gnome-terminal/profiles/Default/background_color "USER_HEX_ENTRY"
    but is it possible to let the user follow the bg command with the USER_HEX_ENTRY value and have the function supply the argument at the end of the command string?


    Cosmic

  2. #2
    Join Date
    Apr 2008
    Location
    LOCATION=/dev/random
    Beans
    5,767
    Distro
    Ubuntu Development Release

    Re: BASH Shell Functions

    Code:
    function bg() {
        gconftool-2 --type string --set /apps/gnome-terminal/profiles/Default/background_color "$1"
    }
    $1 is substituted for the first argument you provide after the bg command.
    Cheesemill

  3. #3
    Join Date
    Nov 2007
    Location
    UK
    Beans
    192
    Distro
    Xubuntu 16.04 Xenial Xerus

    Re: BASH Shell Functions

    Thanks!

    So can I use $2 $3 $3...etc to accept multiple arguments?


    Cosmic

  4. #4
    Join Date
    Apr 2008
    Location
    LOCATION=/dev/random
    Beans
    5,767
    Distro
    Ubuntu Development Release

    Re: BASH Shell Functions

    Yes you can
    Cheesemill

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
  •