My current project involves the use of a .go executable written on Fortran 77 in the mid-eighties. My only access to it currently is through ssh to a server using csh. I have written the following script:
set inpdir = $argv[1]
mkdir ${inpdir}"_out"
set j = 1
while ($j <= 5)
set i = 0
while ($i <= 20)
"tms96-fnl.go <./"${inpdir}"/inp"${j}"0"${i}".d> ./"${inpdir}"_out/out"${j}"0"${i}
set i = i + 1
end
set j = j + 1
end
The result is the message:
tms96-fnl.go <./fftf/inp100.d> ./fftf_out/out100 -Command not found
Syntax error
If i were to key the contents of that message (sans the "-Command not found") while in the same working directory as the script it executes as expected.
The problem is the arrangement of quotes. You have:
"tms96-fnl.go <./"${inpdir}"/inp"${j}"0"${i}".d> ./"${inpdir}"_out/out"${j}"0"${i}
Which would interpret a command that looks like tms96-fnl.go <./. I would do:
tms96-fnl.go < ./"${inpdir}"/inp"${j}"0"${i}".d > ./"${inpdir}"_out/out"${j}"0"${i}"
Related
New to nextflow, attempted to run a loop in nextflow chunk to remove extension from sequence file names and am running into a syntax error.
params.rename = "sequences/*.fastq.gz"
workflow {
rename_ch = Channel.fromPath(params.rename)
RENAME(rename_ch)
RENAME.out.view()
}
process RENAME {
input:
path read
output:
stdout
script:
"""
for file in $baseDir/sequences/*.fastq.gz;
do
mv -- '$file' '${file%%.fastq.gz}'
done
"""
}
Error:
- cause: Unexpected input: '{' # line 25, column 16.
process RENAME {
^
Tried to use other methods such as basename, but to no avail.
Inside a script block, you just need to escape the Bash dollar-variables and use double quotes so that they can expand. For example:
params.rename = "sequences/*.fastq.gz"
workflow {
RENAME()
}
process RENAME {
debug true
"""
for fastq in ${baseDir}/sequences/*.fastq.gz;
do
echo mv -- "\$fastq" "\${fastq%%.fastq.gz}"
done
"""
}
Results:
$ nextflow run main.nf
N E X T F L O W ~ version 22.04.0
Launching `main.nf` [crazy_brown] DSL2 - revision: 71ada7b0d5
executor > local (1)
[71/4321e6] process > RENAME [100%] 1 of 1 ✔
mv -- /path/to/sequences/A.fastq.gz /path/to/sequences/A
mv -- /path/to/sequences/B.fastq.gz /path/to/sequences/B
mv -- /path/to/sequences/C.fastq.gz /path/to/sequences/C
Also, if you find escaping the Bash variables tedious, you may want to consider using a shell block instead.
I need to get the array that I have in my groovy Script and pass it shell Script for further Calculation in the Shell Script
I have tried multiple was but I am not getting the array passed to Shell Script.
templates = ["Temp1","Temp2","Temp3"]
templateCount = templates.size()
sh """
count = ${templateCount}
temp = ${templates}
for (( i=0; i < count; i++ ))
do
echo "Template Name = " ${temp[i]}
done
"""
Try one of the following options.
script {
def templates = ["Temp1","Temp2","Temp3"]
sh """
for v in ${templates.join(' ')}
do
echo \$v
done
"""
// Option 2
for(tmp in templates) {
sh "echo ${tmp}"
}
}
I am able to execute the following from terminal :
matlab -nojvm < span.m
This works fine and produces the required output.
However, in the same directory, if I write a bash script:
#!/bin/bash
matlab -nojvm < span.m
I get the following error when I execute it:
wallShearStresswallsconstant=importdata("wallShearStress_wallBottom.raw");
|
Error: The input character is not valid in MATLAB statements or expressions.
Undefined function 'wallShearStresswallsconstant' for input arguments of type
'double'.
Please let me know what I am doing incorrectly.
The matlab script is as follows and it reads a file (wallShearStress_wallBottom.raw) with 6 columns and 45288 rows (all numbers), for testing purpose dosent matter what numbers are there.
clear all
clc
wallShearStresswallsconstant=importdata("wallShearStress_wallBottom.raw");
ly=110;%64; %nz
lx=407;%239;%nx
ShearStress=zeros(lx,5);
%Uinf=15.894579;
Uinf=16.77;
i=1;
j=1;
k=1;
while i<lx+1
while j<ly+1
ShearStress(i,1)=wallShearStresswallsconstant(k,1);
ShearStress(i,2)=wallShearStresswallsconstant(k,2);
ShearStress(i,3)=wallShearStresswallsconstant(k,3);
if wallShearStresswallsconstant(k,4) < 0
ShearStress(i,4)=ShearStress(i,4)+1;
else
ShearStress(i,5)=ShearStress(i,5)-1;
end
j=j+1;
k=k+1;
end
j=1;
i=i+1;
end
SS = ShearStress;
SS(:,5) = SS(:,4)-SS(:,5);
SS(:,4) = SS(:,4)./SS(:,5);
plot(SS(:,1),SS(:,4))
SS = SS';
fileID = fopen('new.txt', 'w');
fprintf(fileID,'%f %f %f %f %f\n',SS);
Please use the following code instead:
importdata('wallShearStress_wallBottom.raw');
And the common bash command for executing matlab script file is like this:
matlab -nodisplay -nojvm -nosplash -nodesktop -r \
"try, span, catch, exit(1), end, exit(0);"
where span is your .m filename.
I have written some test script for a new machine, but there's an issue that I don't know if it's julia itself or the way I am writting the script.
The julia program is just
module main_prog
println("Program to heat and test a new machine")
println("Does a lot of diagonalizations")
dim = 10
realiz = 5
for ii in 1:realiz
A = randn(dim,dim)
H = (A + A')/2
eig_problem = eig(H)
end
println("End succesful")
end # module
And my bash script is
#!/bin/bash
for i in `seq 1 2`;
do
mkdir job$i
cp diagg_rmt.jl job$i
cd job$i
/home/user/julia/julia ./diagg_rmt.jl &
cd ..
done
When I runt the script, it gives an strange error:
-bash-4.2$ ERROR: getcwd: no such file or directory (ENOENT)
in uv_error at ./stream.jl:1027
in pwd at ./file.jl:8
in abspath at ./path.jl:108
in _include_dependency at ./loading.jl:127
in include_from_node1 at ./loading.jl:296
in process_options at ./client.jl:280
in _start at ./client.jl:378
I have seen another posts of this happening in Ruby, for example, but no idea
what to do here. I am using CentOS Linux release 7.0.1406 (Core)
I'm creating a script like this
#!/bin/csh
set h=1;
while [h=1] do echo "hi"; h=2; done;
but when I execute it a get this:
===> message after : csh test.sh [h=1]: No match.
Try:
set h = 1
while ( $h == 1 )
echo "hi"
set h = 2
end
You seem to be trying to mix Bourne shell syntax into your C shell script.
Csh is generally a lousy language for scripting, try to avoid it if at all possible
http://www.faqs.org/faqs/unix-faq/shell/csh-whynot/
UPDATE:
The csh equivalent to read h is:
set h = $<