Announcement

Collapse
No announcement yet.

variables in bashrc

Collapse
This topic is closed.
X
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    variables in bashrc

    Trying to find out how to use variables in alias's
    for example to shorten
    service blahblah restart to
    restart blahblah

    There may be a resource that explains all this somewhere but I have not been able to find it. Probably just entering the wrong searches.

    Any direction would be appreciated

    #2
    See Bash Shell Functions Tutorial with 6 Practical Examples
    Using Kubuntu Linux since March 23, 2007
    "It is a capital mistake to theorize before one has data." - Sherlock Holmes

    Comment


      #3
      first foray into functions in bashrc. No success. here's what I tried
      Code:
      function restart()
      {
      sudo service $1 restart
      }
      
      function stop()
      {
      sudo service $1 stop
      }
      
      function start()
      {
      sudo service $1 start
      }
      and this is result
      Code:
      virgil@reeser:~$ service apache2 status
       * apache2 is running
      virgil@reeser:~$ stop apache2
       * Stopping web server apache2                                                       * 
      virgil@reeser:~$ service apache2 status
       * apache2 is running
      virgil@reeser:~$ restart apache2
       * Restarting web server apache2
      Maybe I picked a bad service to test on

      Comment


        #4
        or is it related to this error that just started happening
        Code:
        sudo service apache2 restart
        sudo: error in /etc/sudo.conf, line 0 while loading plugin `sudoers_policy'
        sudo: /usr/lib/sudo/sudoers.so must be only be writable by owner
        sudo: fatal error, unable to load plugins
        BTW, I have no idea how to fix this..... yet

        Comment


          #5
          I tested what you did and that works fine for me with mpd, no apache here.
          I did use slightly different naming...

          Code:
          function reserv()
          {
          sudo service $1 restart
          }
          Last edited by otisklt; Oct 06, 2014, 09:56 PM. Reason: clarification
          Kubuntu 18.04 on AMD

          Comment


            #6
            A differet question. I can type alias at a prompt to see what alias's are available. Is there a similiar command to show functions, in case i forget what I called them?

            Comment


              #7
              • declare -F
                list function names
              • declare -f
                list all the functions and their definitions
              • declare -f function
                list one function
              Regards, John Little

              Comment

              Working...
              X