Is it possible to use custom alias for mathematica run? - linux

This is a general question on the use of alias command in linux, but I will take with a mathematica example to be more clear.
I want to creat an alias for mathematica run.
The mathematica run command for a mathematica file myfile1.m is
math -run "<<myfile1.m"
Now if I put this whole command as an alias in bashrc like
alias m='math -run "<<myfile1.m"'
it will run the file when I just type m in terminal.
But I want to know whether there is a way to use in the following way so that it could be used for any mathematica file run in a more sophisticated way :
alias m='math -run "<<file.m? "'
so that from the terminal I can run different mathematica files just typing
m myfile1.m
it will run
math -run "<<myfile1.m"
similarly for anyfile.m one just types
m anyfile.m
and it will run
math -run "<<anyfile.m"

I'd suggest to do something like:
alias m='math -run'
so the command would look like
m "<<anyfile.m"
which is look better, as for me. If you'd like to get deeper, look into this:
Link

With #Bandydan's suggestion the following seems to work.
function m() { math -run "<<$#" ;}

Related

How do you run a standalone ijs j file on Linux?

I have been using j for a few weeks now and loving it. However, all of my work has been in the ijconsole. Does j provide a way to run .ijs files without using load? Similar to how you can simply run $python my_file.py?
I know for windows there exists jconsole.exe, but for Linux and OSx there doesn't seem to be the same option?
You should be able to run bin/jconsole with the .ijs file as the first command line argument.
Here's an example session, copied out of my terminal:
~/j64-807$ cat ex.ijs
d =: 1+1
~/j64-807$ ./bin/jconsole ex.ijs
d
2
I figured out how to get my desired behavior from
https://www.jsoftware.com/help/user/hashbang.htm
The basic idea is to create a "unix script" that points to jconsole by using
#!/home/fred/j64-807/bin/jconsole
at the top of the .ijs file.
Then, you can echo any output you wish or use ARGV to read input.
Finally, call chmod +x your_script.ijs and run using ./your_script.ijs
You can copy the j interpreter files to new projects on servers etc and call them using bash.
So, a final example would be
#!/home/fred/j64-807/bin/jconsole
echo +/*:0".>,.2}.ARGV
exit''
Which computes the sum of squares of digits from command line arguments

Linux command line open any directory

I'm currently using the Linux command line and was just wondering whether there is a quick command you can enter into the console to open any of a given directory.
I'll give you an example of what I mean.
say in a directory ligands/
we have:
ligand_1993324
ligand_1993444
ligand 1993255
shoe_lace
water_bottle
Lets just say there are 100000 of these very similar directories. Because I'm lazy I just want to pick any random one of these, but it has to begin with ligand_199 for example.
Please not I'm trawled through the manual and can't find anything, I've also looked at other stacks, any help would be great!
There are a couple of versions of a program called variously "randomline" or "randline" about. This version shows its age (it's in Perl).
#!/usr/bin/perl
while(<>)
{
push #lines, $_;
}
$randline = $#lines;
$randline = rand($randline);
print $lines[$randline];
Given this in a file ~/bin/randomline, then your task reduces to the following, assuming that you want to open the file with vim:
vim $(ls ligands/ligand_199* | ~/bin/randomline)
You can use following:
files=(/my/dir/*)
file=`printf "%s\n" "${files[RANDOM % ${#files[#]}]}"`
cat file
Maybe something like
number=$(((RANDOM%10000)+1)) && emacs -nw "ligand_199$number" ?

concatenating aliases in linux shell

I would like to concatenate aliases. So for example, if I have the following:
alias aliasone="cat"
alias aliastwo="/etc/passwd"
I would like to be able to type in the shell something like "aliasone+aliastwo" and then the following command will be executed:
cat /etc/passwd
Can this be done?
Thanks!
Aliases are only for command substitution. If you want to have shorthand for arguments, use shell variables.
file=/etc/passwd
cat "$file"
Simply remove the "alias" from the second line. That is:
alias aliasone="cat"
folder="/etc/passwd"
And then you can write:
aliasone $folder
The problem is that alias evaluate commands; but in the second alias there is no command. In the case of a parameter is better to use a variable. If you have a more particular situation (e.g. you are are inside a script) tell us so we can give a better solution.
I think you are trying to run several aliases at the same time, one after another.
I might be wrong, but if this is the case, the easy solution will be to use && in a new alias.
For example you have two existing ones:
alias cdtomydir='cd /home/mydir'
alias listfilesindir = 'll'
then you are able to combine the two above into a third alias by using &&:
alias cdtomydirandlistfiles = 'cdtomydir && listfilesindir'
you can do this: alias aliasone='cat /etc/passwd' then just type aliasone and that's it then if you're going to use cat looking elsewhere then type alias aliastwo='cat /etc/shadow' for example. Anyway just change path and that's it and make sure that aliases are different and keep on mind that words used for commands aren't reserved.
Step 1:
alias ccat='cat $1'
Step 2:
ccat /etc/passwd
Output>>
root:x:0:0:root:/root:/bin/bash
daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin
bin:x:2:2:bin:/bin:/usr/sbin/nologin
sys:x:3:3:sys:/dev:/usr/sbin/nologin
sync:x:4:65534:sync:/bin:/bin/sync
games:x:5:60:games:/usr/games:/usr/sbin/nologin
man:x:6:12:man:/var/cache/man:/usr/sbin/
lp:x:7:7:lp:/var/spool/lpd:/usr/sbin/nologin.............

How to set the following in .cshrc for aliasing

I have following alias in my .cshrc
alias fe-fat "source fat /prj/work"
alias fe-fat1 "source fat1 /prj/work"
I wanted to know if we can set some variable for fat/fat1 and club the above 2 aliases into a single alias somewhat like the below, so that whenever I type fe-<variable> in the Unix terminal the above alias should work
alias fe-<variable> "source <variable> /prj/work"
No, I don't think that's possible with alias.
What are you actually trying to achieve?
It'd be simple enough to write a bash script that launches other commands based on a parameter (so you'd type fe <variable> instead of fe-<variable>).
It's not really worth it with only 2 commands but you could also provide a custom auto-complete script: See Line completion with custom commands
Any particular reason you wouldn't just alias it to something that takes a parameter?
alias fe "source \!:1 /prj/work"
fe fat #=> source fat /prj/work
fe fat1 #=> source fat1 /prj/work

Prolog - SWI specifically - where is pl located?

I'm trying to set up an environment with interprolog and SWI prolog, interprolog needs the location of swi's "pl" but i cant find it. All i can find is swipl or plrc and neither work with interprolog. If i type pl into the terminal(this should run swi-prolog) it says
bash: pl :command not found
but if i type in
swipl
or
prolog
it runs swiprolog fine.
the thing is interprolog requires pl, which i cant seem to find.
anyone have any ideas how i can get around this?
thanks
which swipl
will tell you where the swipl binary lives.
However, you need some way to make "pl" mean the same thing as "swipl"
To do that, you need to alias pl to swipl.
The code alias pl='swipl' will do that in BASH.
so after aliasing, you could start interprolog from the command line and see if it works.
I am not sure if you have it worked out. Ideally, this is what you should do:
Open runSWISPListener.sh.
Change ${SWI_BIN_DIRECTORY}/pl to ${SWI_BIN_DIRECTORY}/swipl
It will then work fine.
Have I understood your question, Is pl a symbolic link to the prolog software? Check the location of the pl executable by where pl or
maybe you need to make the prolog source code .pl executable and add a header at the top of it...
#! /bin/swiprolog -f
; Prolog code here...
And use chmod u+x some_file.pl. Then when bash executes, it checks to see the top bit of the file '#! /bin/swiprolog -f', I'm using the '-f' switch to say pass it into the prolog interpreter...check your documentation...
Hope this helps,
Best regards,
Tom.

Resources