-bash no such file or directory, but it exists - macos

I've recompiled vim with the ruby flag for command-T awesomeness, and I wrote a script that will automatically do this for me on any machine I ssh into (and run the script), but an issue that I'm running into is that when I alias the newly compiled vim, bash throws a no such file or directory at me. Here's what I have:
This works fine:
$ alias v="~/Code/vim"
But when I put this same line in my .bashrc, I get:
-bash: =~/Code/vim: No such file or directory
Even funnier, I put this in my .bashrc:
[ -e "~/Code/vim" ] && echo "found it!"
And that prints "found it!"
I'm not sure if it's a permission issue, but I'm just going to put them here anyway:
-rwxr-xr-x 1 buf staff 2374400 Sep 17 16:27 /Users/buf/Code/vim
What am I doing wrong? I'm running mac os x 10.7

-bash: =~/Code/vim: No such file or directory
It looks like you forgot remove the = sign

Related

Bash: `chmod a+x` Not Working When Run Inside Script

I'm trying to simulate an update process via script.
I only care about the update script's exit code (0 for success and any other value for failure).
I have created a simple script called update.sh to simulate an update:
#!/bin/bash
# 1=true, 0=false
success=1
if [ $success -eq 1 ] ; then
# Success.
exit 0
else
# Failure.
exit 1
fi
To simulate a downloaded update, I have zipped update.sh into a file called update-file.zip.
My main script extracts update-file.zip and runs update.sh:
#!/bin/bash
# Create a fresh update folder.
rm -rfv /test/update && mkdir /test/update
# Simulate download by copying zip file to that folder.
cp -rf /update-file.zip /test/update/
cd /test/update
unzip -o update-file.zip
# Make the update script executable.
updateFile="/test/update/update.sh"
chmod a+x $updateFile
# Run the update.
/test/update/update.sh
if [ $? -ne 0 ] ; then
echo "update failed"
else
echo "update success"
fi
# Delete update folder.
rm -rfv /test/update
However, when I run my main script (even with sudo), I get the following error message:
/test/update/update.sh: Permission denied
Not even using a service (that uses root to do everything) helped, as I still got the same error message.
It seems that chmod a+x is not working when run inside scripts, because if I run chmod a+x /test/update/update.sh on the terminal, everything works fine.
Whenever chmod a+x is run from a script, I get "Permission denied" errors when trying to run the affected script.
What puzzles me is that when I run ls -l /test/update/update.sh, I get the following:
-rwxrwxrwx 1 root root 131 Sep 9 2020 /test/update/update.sh
The output is the same regardless of whether chmod a+x is run from the terminal or a script.
I am on Ubuntu Server 20.04.1 LTS (Focal Fossa).
You may explicitly run the interpreter for the file:
bash /test/update/update.sh
There is no need to make the file executable then.
Could you please use
/bin/bash /test/update/update.sh
instead of
/test/update/update.sh
in script.
Could you please provide output of below command as well once.
ls -ld /test/update

tmuxinator generated bash script ruined by ruby error message that should be on stderr?

So I'm trying to bring me up a tmuxinator (version 1.1) window and panes...and when I do nothing happens...so I run this instead:
leeand00#me-host:~$ tmuxinator debug pwrsh_n_bash
/var/lib/gems/2.4.0/gems/tmuxinator-1.1.1/lib/tmuxinator/project.rb:352: warning: Insecure world writable dir /mnt/c in PATH, mode 040777
#!/bin/bash
# Clear rbenv variables before starting tmux
unset RBENV_VERSION
unset RBENV_DIR
...
and I notice that some ruby library deep, deep down is complaining about a directory being writable at the top of the script that is generated and that's why it won't run...I copied just the bash script into another terminal and it runs just fine.
I went to the file in question:
def extract_tmux_config
options_hash = {}
options_string = `#{show_tmux_options}` # <- THIS BEING LINE 352 from whence the warning came...
options_string.encode!("UTF-8", invalid: :replace)
options_string.split("\n").map do |entry|
key, value = entry.split("\s")
options_hash[key] = value
options_hash
end
options_hash
end
So I figure maybe it doesn't like the permissions on my ~/.tmux.conf, they are a little goofy (thanks MS, every file in my OneDrive is -rw-rw-rw- using this WSL thing).
I try changing it:
$ chmod o-w ~/.tmux.conf
$ chmod g-w ~/.tmux
Now it's permissions are -rw-r--r--
I run tmuxinator debug pwrsh_n_bash again, and I still get the same error message at the top that prevents it from running...
Maybe it's the ~/.tmuxinator folder I think...
chmod -R o-w ./.tmuxinator/
chmod -R g-w ./.tmuxinator/
re-ran $ tmuxinator debug pwrsh_n_bash, still get the error at the top.
I'm aware that I have some of these writable folders on my mounted c drive but I don't understand what that has to do with this warning showing up and preventing me from terminal bliss.
What library causes this issue and how can I shut up it's warning? And shouldn't that stuff be piped out to stderr instead of it showing up in my stdout or the file that this gem is trying to execute after writing it?

Archlinux + MATE Terminal - `.bash_profile` is not being sourced

I am using Arch Linux with MATE as desktop environment. So terminal emulator is MATE Terminal. Recently I installed Jekyll with gem install jekyll. But when I ran jekyll -v it says bash: jekyll: command not found. So I tried to add path of Jekyll to PATH variable.
I ran PATH=$PATH/$HOME/.gem/ruby/2.2.0/bin and it worked perfectly. Now I can run jekyll commands. To add it permanently to PATH variable I edited the ~/.bash_profile file like following. It is not working after reboot. But
source ~/.bash_profile works perfectly.
#
# ~/.bash_profile
#
[[ -f ~/.bashrc ]] && . ~/.bashrc
export PATH="${PATH}:/home/heisenberg/.gem/ruby/2.2.0/bin"
According to ArchWiki this is the proper way to concat something permanantly to PATH. But it isn't working. Can somebody figure me out where the wrong is?
[N. B. : Adding the same line in ~/.bashrc is doing okay.]
Depending on the option it is given, bash can be run as an interactive shell or login shell. The default interactive shell mode does not read ~/.bash_profile. login shell bash do.
See:
First, some setup:
% cat ~/.bashrc
…
export BASHRC="yes"
…
% cat ~/.bash_profile
…
export BASH_PROFILE="yes"
…
Now run a regular (interactive) bash:
% bash
[galaux#magenta ~]$ echo $BASHRC
yes
[galaux#magenta ~]$ echo $BASH_PROFILE
Notice we did not get yes with this last one.
Now with a login shell:
% bash --login
[galaux#magenta ~]$ echo $BASHRC
yes
[galaux#magenta ~]$ echo $BASH_PROFILE
yes
See paragraph INVOCATION from man bash.

Can't run startup.sh as startup despite being installed in PATH

I'm running Ubuntu 14.04. I've created a script called startup.sh and given it execute permissions. I put it in my $HOME/bin folder, and I've checked and this is indeed on the PATH. I've rebooted my computer just to be sure. I am still unable to run startup.sh just as a command (typing startup on the command line). Am I wrong in what I've done or assumed is possible?
My end goal was to be able to just type on the command line "startup" and execute the script I created.
$ startup
startup: command not found
$ echo $PATH
/home/travis/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games
$ cd /home/travis/bin && ls -l
total 4
-rwxrwxr-x 1 travis travis 803 Dec 16 10:08 startup.sh
I can still run the script by navigating to $HOME/bin and running bash startup.sh of course, but that wasn't the goal.
Setting executable permissions and a #!/bin/bash line per How do I run a shell script without using "sh" or "bash" commands? did not work for me as an answer, hence my confusion.
If your file is named startup.sh, then the command to run it needs to be startup.sh.
If you want the command to be startup, don't include any extension on your filename: Just name it startup.

cannot set PATH on .profile

I am new to the MAC OSX and am trying to set my PATH variable. In my .profile I have the following code
# .profile
echo "hello world"
export PATH=/foo:$PATH
When I launch the terminal, I get:
Last login: Thu Oct 23 20:35:54 on ttys000
hello world
➜ ~ echo $PATH
/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin
The file is executed since I see the echo message. However, the $PATH variable does not change at all. Why is that?
EDIT
I've tried to echo out the PATH variable from the script, as follows:
# .profile
echo "hello world"
export PATH=/foo:$PATH
echo $PATH
Which gives me:
Last login: Thu Oct 23 20:53:14 on ttys000
hello world
/foo:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin
➜ ~ echo $PATH
/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin
➜ ~
I don't understand this behavior. The PATH variable is modified while the .profile script is being executed, but resets to the default afterwards. Is that by design or am I doing something wrong here?
Any help would be very appreciated.
EDIT:
Thanks to the comments. I could find the root of the problem: Since I am using zsh, there's also a .zshrc file which is executed after the .profile.

Resources