Results 1 to 8 of 8

Thread: how do I invoke a bespoke extrinsic script language?

  1. #1
    Join Date
    Jan 2008
    Beans
    4,757

    how do I invoke a bespoke extrinsic script language?

    Hi all, I've got a program that I'd like to incorporate a scripting language into. But instead of building one from scratch, I've decided that using bash could be a hell of a lot easier (at least I hope).

    But excluding the general commands to get round, update, mount and symlink the filesystem (the bare neccesities). I don't really know much else!
    But I am getting through prereqs such as "man bash"

    I've come across the word "alias", describes a way of creating extrinsic commands to automate a sometimes complex intrinsic function.
    For example, I could implement
    Code:
     upvar
    as a command to create a link to a variable in a different stack frame.

    I presume that these sorts of details are cached away somewhere in one file. But I'd rather that I'd have mine in it's own folder that can be called using a command.

    ie:
    Code:
     define? myscriptname = "#!/bin/bash {CODE TO LOAD MY ALIAS FILE}"
    As you see I'm a bit in the dark, but any help would be greatly appreciated.

    Thanks in advance.

    Iain

  2. #2
    Join Date
    Apr 2007
    Beans
    14,781

    Re: how do I invoke a bespoke extrinsic script language?

    You can put them in .bashrc, or in a separate file

  3. #3
    Join Date
    Jan 2008
    Beans
    4,757

    Re: how do I invoke a bespoke extrinsic script language?

    Hey,
    Thanks for the info.

    It was a bit vague, but I think I've found my answer... (from reading the .bashrc file)

    Code:
     alias myalias='echo "This is my alias" '
    is how to define one?

    and
    Code:
     alias loadmyalias='. /path/to/my/alias/file'
    adds my list of commands into bash when I need them? (not when the session starts immediately).

    Need confirmation, but if so, I can give this a start tonight.

    Iain

  4. #4
    Join Date
    Jan 2006
    Beans
    Hidden!
    Distro
    Ubuntu 10.10 Maverick Meerkat

    Re: how do I invoke a bespoke extrinsic script language?

    stick the aliases into a file that looks similar to this:

    alias a=ls
    alias ls='ls -l'

    then you can do something like this:

    while line in readline FILE
    do
    $line
    done
    I am infallible, you should know that by now.
    "My favorite language is call STAR. It's extremely concise. It has exactly one verb '*', which does exactly what I want at the moment." --Larry Wall
    (02:15:31 PM) ***TimToady and snake oil go way back...
    42 lines of Perl - SHI - Home Site

  5. #5
    Join Date
    Jan 2008
    Beans
    4,757

    Re: how do I invoke a bespoke extrinsic script language?

    Quote Originally Posted by slavik View Post
    while line in readline FILE
    do
    $line
    done
    Okay, I understand that, but its not the desired effect I'm looking for?
    In other words, this looks more like a batch way of doing things.

    But I understand the purpose of it, though as I said, this for a program I'm writing (Uses mainly C, mixture of other scraps). Sorry for the boldness. But I can do this in C easily, something in the likes of:
    Code:
    file = fopen(str_fpath, "r");
    run_script = popen(str_xpath -x file);
    I'm sure something is wrong with it, but I'll find out when I come to testing.

    Anyway, I think it's solved.

    The way I explained my previous post had the desired effect I wanted.

    Code:
    iain@fredbuntu:~$ hellomsl
    bash: hellomsl: command not found
    iain@fredbuntu:~$ msl_init
    iain@fredbuntu:~$ hellomsl
    HELLO MY SCRIPTING LANGUAGE!
    iain@fredbuntu:~$
    Brilliant!

    Iain
    Last edited by ibuclaw; March 16th, 2008 at 09:02 PM.

  6. #6
    Join Date
    Jan 2008
    Beans
    4,757

    Re: how do I invoke a bespoke extrinsic script language?

    Hi all, sorry to bother again, but I've hit a rock.

    I've only just started to implement this, and the implementations work fine!

    But when I try to execute it in a script, it doesn't seem to work.

    for example, here I've typed in the command in the terminal, followed by executing the command in a script.

    Code:
    iain@fredbuntu:~/$ hellomsl
    bash: hellomsl: command not found
    iain@fredbuntu:~/$ msl_init
    iain@fredbuntu:~/$ hellomsl
    HELLO MY SCRIPT LANGUAGE!
    iain@fredbuntu:~/$ display "This Works..."
    This Works...
    iain@fredbuntu:~/$ ./test
    ./test: line 1: hellomsl: command not found
    ./test: line 2: msl_init: command not found
    ./test: line 3: hellomsl: command not found
    display: Unable to open file (This Works...) [No such file or directory].
    And GraphicsMagick opens too...

    I've tried it on other commands such as ls; which in ubuntu shows blue for directories and green for executable files.
    Through scripts, alas, this shows just grayness, as if it ignores the "~/.bashrc" file altogether.

    I've even tried your way slavik, it proved very helpful in the end. along with "cat $filename"
    But alas, the same problem of not reading the "~/.bashrc" file.

    Before I posted this, I also tried to embed the alias.
    ie:
    alias hello='echo "hello" '
    hello

    But still not getting it.

    So the million dollar question, I suppose is how do I execute scripts with alias'?

    Iain
    Last edited by ibuclaw; March 17th, 2008 at 12:00 AM.

  7. #7
    Join Date
    Jan 2008
    Beans
    4,757

    [SOLVED] Bespoke Extrinsic Script Language

    Code:
    shopt -s expand_aliases
    cat alias_list | while read line; do $line; done
    That was difficult to figure out.

    Oh well, thank you all for your help anyway,
    I wish I knew more about shell script...

  8. #8
    Join Date
    Jun 2006
    Location
    Gwangju, Korea
    Beans
    3,479

    Re: how do I invoke a bespoke extrinsic script language?

    I'd like to open a can of worms and suggest that there are better alternatives to an embedded scripting language than Bash. Bash was made for command line use, and it's great at that. But for interacting with another program, there are several other languages which provide greater power and flexibility without all of Bash's quirks.

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
  •