Why is fish redirection not working as expected - fish

When I try to redirect fish shell output to a file, the command gets put in the file, not the command output. why? This works as expected in bash, zsh etc.
example:
$ fish --version
fish, version 3.2.0
$ rm -f /tmp/foo
$ echo bar > /tmp/foo
$ cat /tmp/foo
echo bar
# expected output:
bar
# It's not related to the echo command. e.g:
$ ls -l > /tmp/foo
$ cat /tmp/foo
ls -l

This seems to have been caused by a bug in fishgretel/fasd
See
https://github.com/fishgretel/fasd/commit/98fb3873aae9adcca2ffc4b4b3958e45d74cb894

Related

Generate a file hash similar to the one output by nix-prefetch-url

Suppose i've got a zip file available under some URL. I need to get its hash, which should be identical to the one output by nix-prefetch-url --unpack <URL>, but without a working Nix installation. How can one do it?
Seems there is no easy way, as nix-prefetch-url adds the file to the store. More details here: https://discourse.nixos.org/t/generate-a-file-hash-similar-to-the-one-output-by-nix-prefetch-url/19907 (many thanks to prompt and thorough community member's response)
Use Docker.
Demo:
$ nix-prefetch-url --unpack https://github.com/hraban/git-hly/archive/06ff628d5f2b02d1a883c94b01d58187d117f4f3.tar.gz
path is '/nix/store/gxx1pfp19s3a39j6gl0xw197b4409cmp-06ff628d5f2b02d1a883c94b01d58187d117f4f3.tar.gz'
164gyvpdm6l6rdvn2rwjz95j1jz0w2igcbk9shy862sdx2rdw9hn
$ # Or .zip: it's the same, because of --unpack:
$ nix-prefetch-url --unpack https://github.com/hraban/git-hly/archive/06ff628d5f2b02d1a883c94b01d58187d117f4f3.zip
path is '/nix/store/1bpjlzknnmq1x3hq213r44jwag1xkaqs-06ff628d5f2b02d1a883c94b01d58187d117f4f3.zip'
164gyvpdm6l6rdvn2rwjz95j1jz0w2igcbk9shy862sdx2rdw9hn
Download to a local directory
$ cd "$(mktemp -d)"
$ curl -sSL --fail https://github.com/hraban/git-hly/archive/06ff628d5f2b02d1a883c94b01d58187d117f4f3.tar.gz | tar xz
$ cd *
And test it:
$ # Using the modern nix command:
$ nix hash path --base32 .
164gyvpdm6l6rdvn2rwjz95j1jz0w2igcbk9shy862sdx2rdw9hn
$ # Or the same, using nix-hash:
$ nix-hash --type sha256 --base32 .
164gyvpdm6l6rdvn2rwjz95j1jz0w2igcbk9shy862sdx2rdw9hn
Same in Docker:
$ docker run --rm -v "$PWD":/data nixos/nix nix --extra-experimental-features nix-command hash path --base32 /data
164gyvpdm6l6rdvn2rwjz95j1jz0w2igcbk9shy862sdx2rdw9hn
$ docker run --rm -v "$PWD":/data nixos/nix nix-hash --type sha256 --base32 /data
164gyvpdm6l6rdvn2rwjz95j1jz0w2igcbk9shy862sdx2rdw9hn
P.S.: I'm not a huge fan of nix-prefetch-url's default output (base32). The default output of nix hash path is better, if you can use it:
$ nix hash path .
sha256-FibesuhNC4M81Gku9qLg4MsgS/qSZ2F3y4aa2u72j5g=
$ # Sanity check:
$ nix-hash --type sha256 --to-base32 $(<<<"FibesuhNC4M81Gku9qLg4MsgS/qSZ2F3y4aa2u72j5g=" base64 -d | hexdump -v -e '/1 "%02x"' )
164gyvpdm6l6rdvn2rwjz95j1jz0w2igcbk9shy862sdx2rdw9hn

Which profile does sh loads

I am trying to load a specific tool ( nvm ) from within sh.
Installing it as explained in the page for bash it works perfectly and testing it returns the following.
$ bash
$ nvm --version
+ X.XX.X
but if I type
$ sh
$ nvm --version
+ sh: 1: nvm: not found
but still its expected as the default installation modifies the .bashrc.
now i have included the same .bashrc code in my /etc/profile
export NVM_DIR="/opt/nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
and tried again.
$ sh
$ nvm --version
+ sh: 1: nvm: not found
$ echo $NVM_DIR
+ /dir/to/nvm
$ [ -s "$NVM_DIR/nvm.sh" ] && echo "it works?"
+ it works?
$ [ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"
$ nvm --version
X.XX.X
which got me extremely confused. What exactly is happening ? Isn't sh loading the /etc/profile or am I doing something really wrong?
--edit after comments--
also tried to include it in the local profile
$ cat ~/.profile
+ export NVM_DIR="/opt/nvm"
+ [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
$ sh
$ nvm --version
+ sh: 1: nvm: not found
The problem was described in this article with the sh blue line.
The solution to the problem was to set the /etc/profile/ in the ENV variable.
for example ENV=/etc/profile sh would load the profile when the sh opens. That solved the problem

Executing multiple commands( or from a shell script) in a kubernetes pod

I'm writing a shell script which needs to login into the pod and execute a series of commands in a kubernetes pod.
Below is my sample_script.sh:
kubectl exec octavia-api-worker-pod-test -c octavia-api bash
unset http_proxy https_proxy
mv /usr/local/etc/octavia/octavia.conf /usr/local/etc/octavia/octavia.conf-orig
/usr/local/bin/octavia-db-manage --config-file /usr/local/etc/octavia/octavia.conf upgrade head
After running this script, I'm not getting any output.
Any help will be greatly appreciated
Are you running all these commands as a single line command? First of all, there's no ; or && between those commands. So if you paste it as a multi-line script to your terminal, likely it will get executed locally.
Second, to tell bash to execute something, you need: bash -c "command".
Try running this:
$ kubectl exec POD_NAME -- bash -c "date && echo 1"
Wed Apr 19 19:29:25 UTC 2017
1
You can make it multiline like this:
$ kubectl exec POD_NAME -- bash -c "date && \
echo 1 && \
echo 2"
The following should work
kubectl -it exec podname -- bash -c "ls && ls"
bin dev etc home proc root run sys tmp usr var bin
dev etc home proc root run sys tmp usr var
If above command doesn't work then try too replace bash with one of the following /bin/bash, sh or /bin/sh
-t
can solve your task
For example, I run here few cmd:
kubectl get pods |grep nginx|cut -f1 -d\ |\
while read pod; \
do echo "$pod writing:";\
kubectl exec -t $pod -- bash -c \
"dd if=/dev/zero of=/feeds/test.bin bs=260K count=4 2>&1|\
grep copi |cut -d, -f4; \
a=$SECONDS; echo -ne 'reading:'; cat /feeds/test.bin >/dev/null ; \
let a=SECONDS-a ; \
echo $a sec"
done
p.s. your example will be:
kubectl exec -t octavia-api-worker-pod-test -c octavia-api -- bash -c "unset http_proxy https_proxy ; mv /usr/local/etc/octavia/octavia.conf /usr/local/etc/octavia/octavia.conf-orig ; /usr/local/bin/octavia-db-manage --config-file /usr/local/etc/octavia/octavia.conf ; upgrade ; head"
Posting here because google search still brings you to this post...
I'd like to throw out using a HEREDOC as an additional possibility.
kubectl exec -i --tty-false PODNAME -- bash << EOF
echo "insert all your commands here."
echo "this subprocess will even pickup any variables you have in"
echo "the shell script that is calling this"
EOF

Trouble installing Sublime command line tools

I followed the advice of this blog post and it didn't work. Below is my output. What can I do to fix this?
~/code/rails/adam $ echo "export PATH=~/bin:$PATH" >> ~/.profile
~/code/rails/adam $ ln -s "/Applications/Sublime Text 2.app/Contents/SharedSupport/bin/subl" ~/bin/subl
ln: /Users/adamzerner/bin/subl: No such file or directory
New output:
~/code/rails/adam $ mkdir ~/bin
~/code/rails/adam $ ln -s "/Applications/Sublime Text 2.app/Contents/SharedSupport/bin/subl" ~/bin/subl
~/code/rails/adam $ subl
-bash: subl: command not found
~/code/rails/adam $ subl --help
-bash: subl: command not found
~/code/rails/adam $
You need to have a ~/bin directory before you can create a symlink in it. Run
mkdir ~/bin
then
ln -s "/Applications/Sublime Text 2.app/Contents/SharedSupport/bin/subl" ~/bin/subl
and you should be all set.

Shell not picking correct path to run drush

I've got drush in /usr/local/bin. Running which drush returns /usr/local/bin/drush. However running drush displays "-bash: /usr/bin/drush: No such file or directory". Running /usr/local/bin/drush works correctly.
My $PATH is /usr/local/bin:/usr/local/mysql/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/opt/X11/bin
[added in an edit] Before I had this issue I removed a copy of the script that was at /usr/bin/drush. It wasn't built correctly.
What on earth could be causing this problem? I do not want to have to type out /usr/local/bin/drush every time; that's why /usr/local/bin is in my $PATH.
Have you run drush before in this shell, then moved it from /usr/bin to /usr/local/bin ? If so, the hash command will show that the shell has remembered the command in the /usr/bin location and will presume it's there without re-checking. Run hash -r will clear this list.
Worked example:
$ echo >/usr/bin/hello 'echo hello'
$ chmod +x /usr/bin/hello
$ hash
hits command
1 /bin/chmod
$ hello
hello
$ hash
hits command
1 /bin/chmod
1 /usr/bin/hello
$ which hello
/usr/bin/hello
$ mv /usr/bin/hello /usr/local/bin/
$ hello
bash: /usr/bin/hello: No such file or directory
$ hash
hits command
1 /usr/bin/which
1 /bin/chmod
1 /bin/mv
2 /usr/bin/hello
$ which hello
/usr/local/bin/hello
$ hash -r
$ hash
hash: hash table empty
$ hello
hello
$ hash
hits command
1 /usr/local/bin/hello