Results 1 to 3 of 3
  1. #1
    Join Date
    May 2004
    Posts
    3

    Unanswered: Newbie Bourne shell function question

    I was just given a temporary UNIX assignment (Bourne shell) and I am unfamiliar with a lot of basics. I added a number of functions to the .profile but our entire group uses this account and I was asked to remove them. I tried simply copying the text from .profile into another file and executing that file but the functions declared in the file were not found when I typed them on the command line. Nobody here knows about or uses functions and they cannot tell me how to make functions available. I Googled tutorials for several hours without finding out how to do this. I don't know if each function has to be in a different file, the filename needs a particular naming convention, or needs to be explicitly added to my path, or if I need to make the file a library. A portion of the code that appears in the file (mbinit) appears below. If anyone can tell me how to make a bunch of functions available to me or point me to an online tutorial that explains it, I would appreciate it.
    Code:
    #!/bin/sh
    # Alias functions for Michael Bailey.
    cls() { clear ; PS1="`pwd`> " ; ls "$@"; }
    clr() { clear ; PS1="`pwd`> "; }
    nd() { cd $* ;  cls; }
    ndhome() { nd /dev01/sherpa; }
    ndext() { nd /projs/sherpa_migration/sherpa_extract; }
    ndmig() { nd /projs/sherpa_migration; }
    ndwork() { nd /projs/sherpa_migration/sherpa_extract/michael/sherpa_extract_10.7/extract/workauth; }
    ndhelen() { nd /projs/sherpa_migration/sherpa_extract/helen/sherpa_extract_10.7; }
    ndmichael() { nd /projs/sherpa_migration/sherpa_extract/michael/sherpa_extract_10.7; }
    ndjr() { nd /projs/sherpa_migration/sherpa_extract/jry/sherpa_extract_10.7; }
    ndsherpa() { nd /projs/sherpa_migration/sherpa_extract/sherpa/sherpa_extract_10.7; }
    ndwa() { nd extract/workauth; }
    Thanks,
    Michael Bailey

  2. #2
    Join Date
    May 2004
    Posts
    3

    Question answered

    I ran across the concept of sourcing the file and that solved my problem. Instead of executing the file, I used . ./filename.

    Thanks,
    Michael Bailey

  3. #3
    Join Date
    Jan 2007
    Location
    Jena, Germany
    Posts
    2,721
    You can also use the "source <file>" bash-builtin. It does the same as ". <file>", but maybe clearer and easier to understand in case this is code that shall be maintained by others in the future.
    Knut Stolze
    IBM DB2 Analytics Accelerator
    IBM Germany Research & Development

Posting Permissions

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