How to make virtualenvwrapper work in fish shell? - shell

Is there any way to make virtualenvwrapper work in fish shell?
When trying to run virtualenvwrapper commands, like workon, I get the following error:
fish: Unknown command 'workon'
And when I run
source /usr/local/bin/virtualenvwrapper.sh
I get a very long error starting with:
fish: Expected a command name, got token of type 'Run job in background'. Did you mean 'COMMAND; and COMMAND'? See the help section for the 'and' builtin command by typing 'help and'.
/usr/local/bin/virtualenvwrapper.sh (line 67): if [ "$OS" = "Windows_NT" ] && [ "$MSYSTEM" = "MINGW32" ]
and ending with:
source: Error while reading file '/usr/local/bin/virtualenvwrapper.sh'

There are a number of alternatives, but the best approach I've found is https://github.com/adambrenecki/virtualfish
That will give you a .fish wrapper around virtualenv with all the virtualenvwrapper commands you are used to.

Related

Bash script error: 'which' command not found

The context of my question is a Silverstripe bash script that I'm trying to execute on a Centos 8 OS shell environment. The script is called sake and the relevant code is:
#!/usr/bin/env bash
if ! [ -x "$(command -v which)" ]; then
echo "Error: sake requires the 'which' command to operate." >&2
exit 1
fi
Executing this, either with or without sudo privilege always results in the following error:
Error: sake requires the 'which' command to operate.
My path is:
echo $PATH
/home/hl/.nvm/versions/node/v16.13.0/bin:/home/hl/.local/bin:/home/hl/bin:/usr/share/Modules/bin:/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin
which exists:
whereis which
which: /usr/bin/which /usr/share/man/man1/which.1.gz /usr/share/info/which.info.gz
I've tried setting a which alias in .bash_profile to /usr/bin/which, but the alias is the same as the command itself, so this was merely an act of desperation.
Suggestions are greatly appreciated.

TensorFlow installation - pip

I am following this guide to install pip: https://www.tensorflow.org/install/pip
When I run this command: . ./venv/bin/activate.fish
I get the following error:
-bash: ./venv/bin/activate.fish: line 4: syntax error near unexpected token -d'
-bash: ./venv/bin/activate.fish: line 4:function deactivate -d "Exit virtualenv and return to normal shell environment"'
Please assist.
thanks
The script activate.fish is intended for fish shell. You're running bash so it's a wrong script for bash. With bash use activate:
. ./venv/bin/activate
The command should be
$ source ./venv/bin/activate
if you are using bash in a Linux machine.

Execute Shell file functions in Mac

I have the following shell file that contains this:
sh
nightlyTag() {
echo $1-alpha.$(date +%Y%m%d).$(($(date +%s%N)/1000000))
}
yarnPubCanaryVersion() {
if [ -z "$1" ]
then
echo "No version argument supplied, maybe you meant v1.0.0?"
return 1
fi
version=`nightlyTag $1`
yarn version --new-version $version --no-git-tag-version
npm publish --tag canary
git reset --hard HEAD
}
I make the file executable with chmod +x canary.sh, then I run it doing ./canary.sh then my terminal changes to sh-3.2$ then I try to run the functions in the terminal like this nightlyTag and I get
sh: nightlyTag: command not found
Same for yarnPubCanaryVersion.
I was looking at this SO question
You won't be able to run functions from the terminal after you run the script.
You need to source the script to do this:
source ./canary.sh
Or add the contents of the file to the .bashrc file or its equivalent, and then source it.
The source command is used to load any function file into the current shell.
Now once you call those functions you will get the expected output.
At the top of your sh file you need to include:
#! /path/to/bash
the path to the bash that you are using.

"rvm use --install" broken in Jenkins, "uname: command not found"

This is a snippet from a Jenkins job run that needs rvm 1.9.3.. I have no idea why the PATH is not being looked at. From this build the PATH environment variable looks correctly set as PATH="/usr/java/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" (as set in /etc/environment), HOME="/scratch" and SHELL="/bin/sh", so I'm mystified by this.
$ bash -c " source ~/.rvm/scripts/rvm && rvm use --install --create ruby-1.9.3 && export > rvm.env"
/scratch/.rvm/scripts/rvm: line 12: uname: command not found
/scratch/.rvm/scripts/rvm: line 15: ps: command not found
bash: rvm: command not found
I have also attempted the rbenv route but am met with similar errors indicating the absence of $PATH
Also, the Jenkins user belongs to the rvm group.
I send many internets in thanks for any assistance offered!
rvm needs login shell.
I use it like this in my builds:
echo "rvm install 2.2.3" | /bin/bash -l
Works just fine this way.

What's wrong with this bash script?

Here's my myscript.sh:
alias apt-get-update="apt-get update -qq"
alias apt-get-install="apt-get install -f -y -qq --force-yes"
alias yum-install="yum --quiet --nogpgcheck -y install"
function ensure_cmd_or_install_package_apt(){
local cmd=$1
shift
local pkg=$*
hash $cmd 2>/dev/null || ( apt-get-update && apt-get-install $pkg )
}
When I run sh myscript.sh I get:
myscript.sh: 5: myscript.sh: Syntax error: "(" unexpected
It looks perfectly fine to me; any ideas?
Does running bash myscript.sh fix it?
It could be your script is running in dash instead of bash.
According to this answer you can change it with the following command:
chsh
Also in general you should be explicit in your script header as to the app/shell you want to run the script with:
#!/bin/bash
If the script requires bash-isms then you should tell it to run with bash.
In your case you are on ubuntu (confirm) and ubuntu uses dash as the default shell (ie /bin/sh is a symlink to dash). Dash doesn't allow:
function name () {}
and instead just wants:
name () {}
In fact the first form should be avoided if possible since it's not portable. But if you use the function keyword, don't use parens since they are not required (it's an accident that it even works).
With regards to setting a script header, sometimes it's better to use env to find the program (say in the case of ruby or perl for instance where you might have numerous ruby/perl executables but the one furthest up on your path is the one you want to run with).
#!/usr/bin/env ruby
Is the way to go. Usually for shells, /bin/bash or /bin/csh etc is sufficient in your shebang, but never assume :).

Resources