Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9196001
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T21:45:14+00:00 2026-06-17T21:45:14+00:00

Background: I’m trying make a function that runs commands on a set interval because

  • 0

Background:

I’m trying make a function that runs commands on a set interval because I don’t have access to a “watch” program. Simplified to it’s most basic from, the function I’m trying to write is runit() { $1; }.

What works:

This works fine and dandy when I pass it things that aren’t aliases. For example, runit "ls -l" works fine. I get the full output from the ls -l command.

What doesn’t work:

The problem starts when I pass it an alias. For example, setting alias ll="ls -l" then calling runit "ll" will result in -bash: ll: command not found.

Things I have tried:

When I hard-code the alias runit() { ll; }, it works fine and gives me what I expect.


I feel like I might be overlooking something, but I can’t quite place my finger on it.
Why would hard-coding the alias work fine, but passing it into the function fail?
Is there a way to accomplish what I’m attempting to do?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T21:45:15+00:00Added an answer on June 17, 2026 at 9:45 pm

    From the bash man page discussion of aliases (emphases mine):

    Aliases are expanded when a command is read, not when it is executed.
    Therefore, an
    alias definition appearing on the same line as another command does not take effect until the next line of input is read. The
    commands
    following the alias definition on that line are not affected by the new alias. This behavior is also an issue when functions are
    executed. Aliases are expanded when a function definition is read, not when the function is executed, because a function
    definition is
    itself a compound command. As a consequence, aliases defined in a function are not available until after that function is executed.
    To
    be safe, always put alias definitions on a separate line, and do not use alias in compound commands.

    You can observe this effect in functions by using the type command:

    $ run_it () { ll; }
    $ type run_it
    

    You should see that the body of the function contains a call to ls -l, not ll.

    The last sentence of the section on aliases:

    For almost every purpose, aliases are superseded by shell functions.

    My interpretation of that line is: if you think you want to use an alias, try writing a function first. Don’t use an alias unless the function demonstrably fails to do what you need.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Background I am trying to build a Java program that make use of an
Background: I would like to dismiss a modalView that I have presented earlier and
Background I have a rails 3 app that has a model named A with
Background - I have a webpage that contains a bunch of buttons (think POS
Background: I have a UITableView which has three rows with custom UITextFields that are
Background I have a SQL dataset that is called as a view via LINQ-to-Entities.
Background: I have a set of point which I run through a convex hull
Background I have an embedded system which runs an application originally written in C++
Background: I have a Hash that I am iterating through to print it in
Background I have a joined table consisting of Incidents, Customers, and Areas that I'm

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.