I am new to babashka. When I run a script it appears to do nothing. On cygwin:
$ bb --version
babashka v1.1.172
$ bb '(+ 1 2 3)'
6
$ echo '(+ 1 2 3)' > t.clj
$ cat t.clj
(+ 1 2 3)
$ bb t.clj
<== nothing here!
The same thing is happening on the Windows command prompt.
never mind - the --prn option worked:
$ bb --prn t.clj
6
However, the related section on the babashka book has the script just like I have it on my question and does not mention the need to use the --prn option
Related
In J console mode if I type ARGV I get the full path of jqt.exe But when I try to pass some strings to a J script file I get 'syntax error' or 'domain error'. How does argument passing and retrieval or display work?
If you want to write to a file you would pass the information using
'string' 1:!2 'filepath/jscriptfile'
see https://www.jsoftware.com/help/dictionary/dx001.htm
if you want to pass an argument to a verb declared in a script, you would first have to load the script
load 'filepath/jscriptfile'
Then as long as the script contains verbs that have been assigned using =: so that the verb is not local to the script file, you would pass the string to the verb, which has now been loaded.
verb 'string'
An interaction with a script that just prints out its arguments:
$ cat args.ijs
#! /usr/bin/env j
exit echo each ARGV
$ ./args.ijs
j
./args.ijs
$ ./args.ijs 1 2 3
j
./args.ijs
1
2
3
$ ./args.ijs '1 2' 3
j
./args.ijs
1 2
3
ARGV is a list of the boxed arguments to the script. It works like any list of boxed literals, and if you're a domain error it's from some verb in your script that's given arguments it's not defined to handle. If you're getting a syntax error it's because there's something in your script with incorrect syntax. This is unrelated to ARGV as such.
Perhaps you're expecting numerical arguments to be numbers? Arguments are always delivered as strings. Here's a slightly more involved script with usage, that prints the sum of the factorials of its arguments:
#! /usr/bin/env j
sumfact =: [: +/ [: ! x:
3 : 0''
if. (#ARGV) > 2 do.
echo sumfact > 0&". each 2}.ARGV
exit 0
else.
echo 'usage: ', (1{::ARGV), ' <n1> [<n2> ... <nn>]'
exit 1
end.
)
As used:
$ ./sumfact.ijs
usage: ./sumfact.ijs <n1> [<n2> ... <nn>]
$ ./sumfact.ijs 0
1
$ ./sumfact.ijs 5
120
$ ./sumfact.ijs 5 5 5
360
$ ./sumfact.ijs 100
93326215443944152681699238856266700490715968264381621468592963895217599993229915608941463976156518286253697920827223758251185210916864000000000000000000000000
The text after #! isn't important; I use /usr/bin/env j because I have a j in my path that's the usual bin/jconsole of a J installation.
Cell1.1.annot.gz
Cell1.2.annot.gz
Cell1.3.annot.gz
Cell1.4.annot.gz
Cell1.5.annot.gz
Cell2.1.annot.gz
.
.
.
Cell3.5.annot.gz
Making for a total of 3 X 5 = 15 files. I would like to run a python script on them. However, the catch is that each number (clarified here:Cell2.NUMBER.annot.gz) has to be matched to another file in a separate directory. I have code that works below, although it only works for one Cell file at a time. How can I automate this so it works for all files? (So Cell1...Cell3?)
for i in `seq 1 5`;
do python script.py --file1 DNA_FILE.${i} --file2 Cell1.${i}.annot.gz --thin-annot --out Cell1.${i} ;done
Another loop?
for c in 1 2 3
do for i in 1 2 3 4 5
do python script.py --file1 DNA_FILE.${i} --file2 Cell${c}.${i}.annot.gz --thin-annot --out Cell${c}.${i}
done
done
I have a folder 'foo' which consist of file 'foo.v'. foo.v is a symlink to another file
foo.v -> ../foo2/foo.v
Now, I copy (or create link) another foo.v at first location (foo/) so that it becomes symlink to another file along with its original source file
- foo.v -> ../foo3/foo.v
- ../foo2/foo.v -> ../foo3/foo.v
Is something like this possible in linux ?
A symlink can point to a symlink:
$ echo test > 1
$ ln -s 1 2
$ ln -s 2 3
$ cat 3
test
$
These files look like this:
1
2 -> 1
3 -> 2
When moving or copying a symlink it behaves just like a file - the content is not changed:
$ cp 2 3
This would look like this:
1
2 -> 1
3 -> 1
I'm working on a function which is intended to analyse result of executing emerge --pretend $package, and set USE flag in make.conf, and then execute emerge $package. Example code as below, at line 5, emerge --pretend worked fine, but at line 13, I got an error emerge: command not found.
Even if I removed the parenthesis between line 8 and line 15, nothing changed, same error, any idea? If replacing emerge with echo, same error, echo: command not found. It seemed both outside and inside of while loop are not at the same shell. Why and how to solve that?
Thank you very much!
1 #/bin/bash
2 function emgRecursion() {
3 local result
4 local str
5 result="$(emerge --pretend "="$1 | grep "\[ebuild")"
6 while read -r line
7 do (
8 if [[ $line = *"USE=\""* ]]; then
9 echo "====="
10 else
11 str="${line#*"] "}"
12 str="${str%%" "*}"
13 emerge --pretend "="$str
14 fi
15 ) </dev/tty
16 done <<<"$result"
17 }
18 emgRecursion "sys-cluster/ceph-0.94.4"
This question already has answers here:
Indirect variable assignment in bash
(7 answers)
Closed 7 years ago.
Here is the scenario:
suppose I set positional variables:
set 1 2 3 4
eval "args_$1=something"
how do I read args_1,args_2,args_3... variables
I tried
echo $args_$1
and this also not working
eval "\$$(echo arg_$1)"
How do I get value of $arg_1, to display on terminal or pass to a function, etc.
Without eval:
$ set 1 2 3 4
$ var="args_$1"
$ declare "$var=foo"
$ echo "$var"
args_1
$ echo "${!var}"
foo
This uses an indirect variable.
$ set 1 2 3 4; eval arg_$1=koba; eval echo $`echo arg_$1`
koba
PS: Using eval is not recommended.