I am unfortunately having to use windows in work, and so I have installed win-bash to have a unix shell running. all going well but I am having an issue running the following .sh file:
bash $ ./qf.sh
.\qf.sh: option not available on this NT BASH release
.\qf.sh: fork: Bad file descriptor
qf.sh is:
#!/bin/bash
cat test.csv | while read line
do
echo "${line//,/ }" | xargs ./adder
done
I find it hard to believe someone would create a bash emulator incapable of running a bash file. curious that the error message writes .\qf as opposed to ./qf
Can anyone shed some light on this?
use MinGW or Cygwin
MinGW: http://sourceforge.net/projects/mingw/files/?source=navbar
Cygwin: http://www.cygwin.com/
Using Cygwin absolutely killed this error for me. I do wonder however, how this should work with MinGW. I don't see any unix command executable directory to include in the path (like cygwin64\bin with Cygwin)
Related
I´m currently writing a snakemake pipeline, for which I want to include a perl script.
The script is not written by me, but from a github page. I never worked with perl before.
I installed perl (5.32.1) via conda. I have installed miniconda and am working on my universities unix server.
The code for my perl script rule looks like this:
rule r1_filter5end:
input:
config["arima_mapping"] + "unprocessed_bam/{sample}_R1.sam"
output:
config["arima_mapping"] + "filtered_bam/{sample}_R1.bam"
params:
conda:
"../envs/arima_mapping.yaml"
log:
config["logs"] + "arima_mapping/r1_filter5end/{sample}_R1.log"
threads:
12
shell:
"samtools view --threads {threads} -h {input} -b | perl ../scripts/filter_five_end.pl | samtools -b -o {output} 2> log"
When I run this I receive the following error:
Can't open perl script "../scripts/filter_five_end.pl": no such file
or directory found
From what I learned while researching is that the 1. line of a perl script sets the path to my perl executable. The script I downloaded had the following path:
#!/usr/bin/perl
And since I use perl installed via conda this is probably wrong. So I set the path to:
#!/home/mi/my_user/miniconda3/bin/perl
However this did still not work, regardless of if I call
perl ../scripts/filter_five_end.pl
or
../scripts/filter_five_end.pl
Maybe it´s just not possible to run perl scripts via snakemake?
Anyone who had encountered this specific similar case?^^
The problem is not with the shebang. The interpreter path in the shebang doesn't matter because you're calling it with perl ../path directly. The shell that this command is executed in will resolve the path to the perl program (which is very likely the conda one) and then run the script, only taking flags (like -T or -w) from the shebang inside the script.
The error message means it cannot find the actual script file. I suspect when you run that shell command, it's in the wrong directory. Try a fully qualified path.
As stated by OP in their comment:
I forgot that snakemake always looks files up from the Snakemake file not the directory the rules are saved in.
Not quite an answer but perhaps relevant:
I forgot that snakemake always looks files up from the Snakemake file not the directory the rules are saved in.
This is not entirely correct, I think. The reference point is the directory set by -d/--directory which by default is where you execute snakemake:
--directory DIR, -d DIR
Specify working directory (relative paths in the snakefile will use this as their origin). (default: None)
So I was trying to create little .sh script for my work and run into one little problem.
My cygwin terminal (x64) runs just fine and I'm using it often enough to do manual greps.
In the begging I had some issues with this command but now it works fine in cygwin terminal.
Once I wrote my little script and tried to run it only output I'm getting is "line 6: grep: command not found"
My execution method is:
Open cygwin terminal
cd to script location
type in ./script.sh
enter :)
Anyone knows how to fix that? I already added cygwin bin folder to my system path (Win 10 btw) but that didn't helped. Looked around for a while but haven't found anything useful, mostly issues with grep itself.
my script for reference:
mkdir -p output
PATH=$PWD"/output"
while IFS=";" read -r component location global
do
cd $location
grep -iRl $global --exclude-dir={wrongdir1,wrongdir2} > $PATH"/"$component".txt"
done < input.csv
you're overwriting you Cygwin system path: PATH=$PWD"/output" - instead of PATH use a diff var name.
I have had a hard time in executing my shell scripts on bash on Ubuntu on windows 10. The script is very simple:
# file name: submission.sh
echo "Hello world" > output.txt
When I executed it with a command sh submission.sh, it gave me an error:
$ sh submission.sh
: Directory nonexistentssion.sh: cannot create output.txt
However, when I changed the script into
# file name: submission.sh
echo "Hello world"
and executed it with the same command sh submission.sh, it gave me the right output
$ sh submission.sh
Hello world
It seems like bash on Ubuntu on Windows cannot get it right when the script involves directing the output to a file. Is there any solution or workaround to this?
EDIT:
Details on my system:
Program: "Bash on Ubuntu on Windows"
OS: Windows 10 Version 1709
EDIT:
Typing the command directly on the terminal works, i.e.
$ echo "Hello world" > output.txt
$ cat output.txt
Hello world
I still wants to put the commands on a file and execute the file instead of writing the command directly to the terminal, and this is still unsolved.
You appear to have mangled text in nonexistentssion.sh: and No such file or directorytput.txt which suggests you might have Windows line-endings in the file \r. If you created the script using a Windows program (like Notepad) then that could be the case.
If you have dos2unix then run it on your script and try again.
By the way for future reference, running sh is not the same as running bash. In this case it would have made no difference, but sh is a POSIX shell, full bash has many extensions which will not work under sh.
Some platforms run sh as a symbolic link to bash which fools people into thinking they are the same, but bash detects this and switches to POSIX mode when running as sh. It is a common issue here.
In your submission.sh file, is better to add a shebang as first line.
Another thing you want to consider if you want to use sh instead of bash is to replace echo with printf, for portability
Your code should look something like:
#!/bin/bash
printf "Hello world!\n" > output.txt
You can call it simply by ./submission.sh and because of the shebang, your terminal will know how to open it [:
P.S. Keep in mind that because of the standard umask in Ubuntu, you might want to execute chmod u+x submission.sh before running it.
Also, notice that your error is probably caused by a permissions issue.
Try adding write permissions in the folder you are launching the script.
I'm trying to run gitk on Windows but the console gives me:
'gitk' is not recognized as an internal or external command,
operable program or batch file.
But then, I can do
> where gitk
C:\Program Files (x86)\Git\bin\gitk
How comes?
UPDATE: Stealing the OP's comment:
Thanks for a (lengthy) explanation, the easiest fix for me was to move from the old msysGit (1.9.5) version to the newer "Git for Windows" builds which has a proper Windows wrapper for gitk.
gitk, unlike most git commands, is a shell script that invokes Tcl.
If you examine the gitk executable file itself, its first few lines are:
#!/bin/sh
# Tcl ignores the next line -*- tcl -*- \
exec wish "$0" -- "$#"
(At least that's what it looks like on my Linux system; the Windows installer for gitk might change that.)
On a Unix-like system, that first line, known as a "shebang", tells the system to invoke /bin/sh to execute the file rather than executing it directly.
The third line executes the wish command, which executes the script as a Tcl script.
If you have Tcl installed on your Windows system, you should be able to run gitk as a Tcl script using something like this:
C:\> tclsh "C:\Program Files (x86)\Git\bin\gitk"
(Disclaimer: I have not tried this.)
You might also be able to change the command's name from gitk to gitk.tcl and set up a file association in Windows so it will be invoked correctly. (I'm a little surprised that the Windows git installer didn't do this for you.)
More information on running Tcl scripts on Windows can be found here.
And this question discusses invoking gitk on Windows from the context menu rather than from the command line.
Using Cygwin I can use rysnc as expected, but using the same rysnc command from a shell file I see:
'rsync: command not found'
Script is:
#!/bin/sh
echo 'Moving local media to dev server'
rysnc -vruz --progress -chmod=0755 --exclude catalog/product/cache media user#domain:/var/sites/folder/folder
execution:
$ ./script.sh
Looks like a typo to me. Change rysnc to rsync.
PS: Don't type in error messages. Cut and paste them. Each and every character is important to diagnose the problem.
Perhaps cygwin is not installed on your machine. Install it from the Cygwin setup.exe that can be downloaded on www.cygwin.com