Jupyter notebook executing bash without repeated ! prefix - jupyter

I have a notebook that does the following
%cd SOME_DIRECTORY
./sandbox stuff param1 param2
./sandbox bla bla
But this doesn't work, however if I do
%cd SOME_DIRECTORY
!./sandbox stuff param1 param2
!./sandbox bla bla
It works, the issue is that I have to add ! to every single line, is it possible to change this?

Related

Windows Make - No rule to make target 'echo'

I'm begginer with Make and i'm stuck with the most simple makefile, I think.
I wrote the following makefile :
hello:
echo "hello world"
And when I do in Windows Powershell :
PS C:\Users\Thibault\Documents\repo\myfolder> echo "hello world"
hello world
PS C:\Users\Thibault\Documents\repo\myfolder> make
make: *** No rule to make target 'echo', needed by 'hello'. Stop.
Thanks for any help

How would I make a custom Powershell Command?

I would like to make a powershell command, such as startcode that should go to a different folder, and run a python file. I want this command to be accessible from ANY directory that my powershell terminal is in. I made a powershell program with this so far:
function startcode() {
cd ~
cd Blah blah blah
echo 'Starting!!'
python hello.py
}
How would I make the command startcode available everywhere?

How to put a comment after a IPython magic command

How can I put a comment at the end of an IPython magic command?
Eg, trying to use %cd:
%cd "dir" # comment
I want to change to directory dir but instead I get:
[Errno 2] No such file or directory: 'dir # comment'
It's not possible in general because IPython magic commands parse their own command lines.*
There are some magic commands where comments seem to work, but actually they're being handled in another way. For example:
%ls # comment works properly, but %ls is an alias to a shell command, so the shell is what's parsing the comment.
%automagic 0 # comment behaves like %automagic, toggling the setting instead of exclusively disabling it like %automagic 0 would do. It's as if the 0 # comment is all one string, which it ignores.
%run $filename # comment treats the comment as arguments, so ['#', 'comment'] ends up in sys.argv for $filename.
Workaround
You could call magic commands using exclusively Python syntax.
First get the running IPython instance with get_ipython():
ipython = get_ipython()
Then:
ipython.run_line_magic('cd', 'dir') # comment
Docs: InteractiveShell.run_line_magic()
Or for cell magics, you could go from this (which doesn't work):
%%script bash # comment
echo hello
to this:
ipython.run_cell_magic('script', 'bash', 'echo hello') # comment
Docs: InteractiveShell.run_cell_magic()
Another option, I suppose, is to run an entire cell, although, suppressing the output since it returns an ExecutionResult object:
ipython.run_cell('%cd dir'); # comment
Docs: InteractiveShell.run_cell()
* I'm not sure if this is documented explicitly, but it is documented implicitly under defining custom magics, and I found the clues in this GitHub issue: Allow comments after arguments in magic_arguments.
TL;DR: You cannot as things stand. This might or might not be an error in the implementation of %cd.
Until this is fixed, one way to avoid this is to use:
import os
os.chdir("dir") #some comment here
A second alternative is using bash commands.
However % is a magic command, not equivalent to a bash command. This is on purpose,
as it can change the current directory of the notebook.
This is not the same as e.g.
!cd dir #some comment here
Which will spawn a shell and execute the command there thus not changing the current directory. (You can verify using pwd before/after each command)
Note that if your goal is not to change the current jupyter notebook directory, you can issue multiple commands in one cell with the magic
%sh:
%%sh
cd dir #some comment here
ls #some more commands here
....
This command will spawn a shell and all bash commands will be executed there, so the current jupyter directory will not change.

Why does Scala ignore exclamation points in command line arguments?

If I write a Scala script (or App) that just prints out the command line arguments, I notice that it ignores all the '!' characters. For example, if my script looks like:
println(args(0))
And I run it with:
scala MyScript "Hello!"
I get the output:
Hello
And if I run it with:
scala MyScript "Hello! World!"
I also get:
Hello
What's going on? What is the purpose of the ! character in arguments that causes this behaviour?
! is history substitution.
Try scala MyScript hello! with ! at EOL to see it work as if quoted.
http://www.gnu.org/software/bash/manual/bashref.html#Event-Designators
http://www.gnu.org/software/bash/manual/bashref.html#Single-Quotes
On windows, the "scala.bat" command script has delayed expansion enabled.
http://en.wikibooks.org/wiki/Windows_Batch_Scripting
http://en.wikibooks.org/wiki/Windows_Batch_Scripting#SETLOCAL
http://en.wikibooks.org/wiki/Windows_Batch_Scripting#Command-line_arguments
To disable interpretation of !myvar!:
C:\Users\you> scala greeting.script "hello^!"
hello!
C:\Users\you> set world= Bob
C:\Users\you> scala greeting.script "hello!world!"
hello Bob

fish runs some functions in .config/fish/config.fish while sourcing

I'm trying the fish shell, and it seems to run some functions I've defined in it's config file when I open a new fish tab. For example, if I have this function:
function foo
cd ~/
end
fish will go into an infinite loop as it constantly cd's into my user directory and sources the file. But if I have this:
function foo
ls
end
fish won't show me the output of ls. What is going on?
you may have defined foo as a function and it creates a infinte loop in someway.
try this
function foo
command ls
end