I created a couple of custom bash scripts that does some simple things like starting and stopping a PostgresSQL server. I have them stored in a specific directory of my choice.
Joes-MacBook-Pro:scripts joe$ l
total 24
-rwxr-xr-x 1 joe staff 124B Apr 18 21:22 pgstart
-rwxr-xr-x 1 joe staff 114B Apr 18 21:23 pgstatus
-rwxr-xr-x 1 joe staff 123B Apr 18 21:22 pgstop
Joes-MacBook-Pro:scripts joe$ pwd
/Users/joe/Softwares/scripts
I have even referenced these scripts in my .bash_profile as:
# Custom Scripts
export SCRIPTS_HOME=/Users/joe/Softwares/scripts
Now when I tried to use it as:
Joes-MacBook-Pro:~ postgres$ pgstart
-bash: pgstart: command not found
Should I place this script in the /bin/ directory on my Mac? Any clues?
I am no Mac-Expert, but based on linux, it should suffice to do the following in your .bash_profile:
export SCRIPTS_HOME=/Users/joe/Softwares/scripts
export PATH=$PATH:$SCRIPTS_HOME
You could omit the first line, and replace it accordingly.
Don't forget to restart your terminal, or to source your .bash_profile
Add this to your ~/.bash_profile:
PATH=$PATH:/Users/joe/Softwares/scripts
Restart Terminal and it will work.
run source ~/.bash_profile to engage the export.
However, prior to that add: PATH=$PATH:$SCRIPTS_HOME to your bash_profile so your executable can be found via command line.
Related
csshX not working on Mac Big Sur.
Unimplemented: POSIX::tmpnam(): use File::Temp instead at /System/Library/Perl/5.28/darwin-thread-multi-2level/POSIX.pm line 185. Unimplemented: POSIX::tmpnam() at /usr/local/bin/csshX line 1130. BEGIN failed--compilation aborted at /usr/local/bin/csshX line 1130.
I have FIXED IT!
The whole thing was that Apple used in MacOS Catalina perl 5, version 18, subversion 4 (v5.18.4) as a default, but in Big Sur perl 5, version 28, subversion 2 (v5.28.2)
csshX is not compatible with 5.28 so the easiest way is to change the default one by this command:
defaults write com.apple.versioner.perl Version -string 5.18
since Apple kept the previous version:
sh-3.2# ls -l /usr/bin/perl*
-rwxr-xr-x 1 root wheel 140176 Jan 1 2020 /usr/bin/perl
-rwxr-xr-x 1 root wheel 139184 Jan 1 2020 /usr/bin/perl5.18
-rwxr-xr-x 1 root wheel 121472 Jan 1 2020 /usr/bin/perl5.28
-rwxr-xr-x 1 root wheel 121472 Jan 1 2020 /usr/bin/perl5.30
and Voilà - csshX is working again!
change line create tmp file in CsshX.iterm
use POSIX qw(tmpnam);
by
use File::Temp qw(tmpnam);
Replace first line of the csshX with perl5.18 version.
Edit csshX file and replace the first line #!/usr/bin/perl with #!/usr/bin/perl5.18
On Ventura exec:
defaults write com.apple.versioner.perl Version -string 5.30
Edit /usr/local/bin/csshx, change line 1130 from POSIX to File::Temp
use File::Temp qw(tmpnam);
I fixed mine by
add the write permision for all user on the file /usr/local/bin/csshX
chmod ugo+w /usr/local/bin/csshX
edit the file /usr/local/bin/csshX by updating the first line from #!/usr/bin/perl with #!/usr/bin/perl5.18
Following this post I installed brew and then reinstalled ocaml to include graphics:
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
brew cask install xquartz
brew reinstall ocaml --with-x11
But after restarting my computer, when I tried to run an ocaml program that used graphics I got the error
Error: Cannot find file /Users/.../.opam/4.03.0/lib/ocaml/graphics.cma
The post also said:
Finally remember to check that the instance of ocaml that is running
is the one in /usr/local/Cellar/objective-caml/x.yy.z[_w]/bin, and
if it isn't then prepend that url to your PATH environment
variable.
How do I do check the instance of ocaml that is running? And what does the poster mean by "prepending that url to your PATH environment"?
I've tried changing my directory to that path, but I get an error:
$ cd /usr/local/Cellar/objective-caml/
-bash: cd: /usr/local/Cellar/objective-caml/: No such file or directory
If someone could please tell me what I need to do to get graphics.cma working that would be great!
UPDATES:
I've tried creating .bashrc and putting in
alias ocaml="/usr/local/Cellar/ocaml/4.04.0/bin/ocaml”
Yet with no avail...I'm quite lost on what to do. If anyone could give me an inkling of what to do that would be great!
(Note: I put 4.04.0 instead of 4.03.0because when I explored the directory /usr/local/Cellar/ocaml/4.03.0/bin/ocaml but the directory /usr/local/Cellar/ocaml/4.04.0/bin/ocaml does)
How do I do check the instance of ocaml that is running?
If your question is: what program is running when you type ocaml in a terminal window at the shell prompt (or more generally thru execvp and other functions)? then you should use the which ocaml command.
And what does the poster mean by "prepending that url to your PATH environment"?
Read more about the PATH variable. It is often set in your ~/.bashrc file (which you should probably and carefully edit once using your favorite editor) -or some other bash initialization file- if your interactive shell is bash. You should check what it is with the echo $PATH command. See also this. Notice that ~/.bashrc is expanded by your shell during globbing. Read also the documentation of bash notably the Bash Startup Files chapter.
If you are using opam you should read its documentation. Notably this question (mentioning PATH) from its FAQ.
Since aliases are mostly for interactive shells, defining an alias is not enough for most shell scripts. You really need to change your $PATH and/or add files (or symlinks) in directories mentioned in it.
PS. Understanding the role of PATH and how to set it is mandatory for serious use of the command line, notably on POSIX systems.
In general, homebrew puts all its binaries, libraries and settings in /usr/local/Cellar/PACKAGENAME/VERSIONNUMBER but it also creates symbolic links in /usr/local/bin that point to the latest package/version.
So, if you look at my /usr/local/bin you will see:
ls -l /usr/local/bin
Output
lrwxr-xr-x 1 mark admin 26 30 Jan 2016 ack -> ../Cellar/ack/2.14/bin/ack
lrwxr-xr-x 1 mark admin 43 11 Oct 13:30 amqp-consume -> ../Cellar/rabbitmq-c/0.8.0/bin/amqp-consume
lrwxr-xr-x 1 mark admin 49 11 Oct 13:30 amqp-declare-queue -> ../Cellar/rabbitmq-c/0.8.0/bin/amqp-declare-queue
lrwxr-xr-x 1 mark admin 48 11 Oct 13:30 amqp-delete-queue -> ../Cellar/rabbitmq-c/0.8.0/bin/amqp-delete-queue
lrwxr-xr-x 1 mark admin 39 11 Oct 13:30 amqp-get -> ../Cellar/rabbitmq-c/0.8.0/bin/amqp-get
lrwxr-xr-x 1 mark admin 43 11 Oct 13:30 amqp-publish -> ../Cellar/rabbitmq-c/0.8.0/bin/amqp-publish
lrwxr-xr-x 1 mark admin 28 17 Jul 22:49 7z -> ../Cellar/p7zip/16.02/bin/7z
lrwxr-xr-x 1 mark admin 29 17 Jul 22:49 7za -> ../Cellar/p7zip/16.02/bin/7za
lrwxr-xr-x 1 mark admin 29 17 Jul 22:49 7zr -> ../Cellar/p7zip/16.02/bin/7zr
lrwxr
As you can see, ack points to version 2.14 of ack in the Cellar and so on.
In general therefore, when using homebrew, you should not directly use anything in the Cellar because that is version-specific. Instead, you should use /usr/local/bin and rely on that pointing to the latest/greatest thing in the Cellar. That way you won't have pain when upgrading and you won't have to change all your app-1.01 to app-1.0.2 in all your scripts because you will just be using app (which, by virtue of your PATH, means /usr/local/bin/app) instead of anything version-specific.
So, I would suggest you edit your bash profile, using TextEdit like this:
open -e ~/.profile
and add this line at the end:
export PATH=/usr/local/bin:$PATH
Remove all your version-specific aliases and log out and then back in again.
I'm trying to do the simplest of shell aliases like I always use to do.
Here's my .bashrc (and same happened with ZSH and .zshrc) for instance :
alias ll=“ls -al”
alias edit_http=“open -e /etc/httpd/conf/httpd.conf”
and here's my $PATH variable :
/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
When I open a new terminal window I get this :
-bash: alias: -al”: not found
-bash: alias: -e: not found
-bash: alias: /etc/httpd/conf/httpd.conf”: not found
Here's my ls -al result of .bashrc :
-rwxr-xr-x# 1 ed staff 78 Mar 17 03:55 .bashrc
Strangely I can type this into Terminal and it works :
alias ll="ls -al"
But not from within the .bashrc file.
Any suggestions ? I've checked so many forum entries and nothing worked so far.
It looks like something went wrong during copying the alias into your .bashrc.
You ended up with 'wrong' quotation mark. Replace “ with "and it should work. “ is unicode but you require ascii quotation marks. For testing you can use this .bashrc
# bashrc example
# won't work
alias ll=“ls -al”
# will work
alias la="ls -al"
And with this code you can verify your problem:
$ source .bashrc
-bash: alias: -al”: not found
$ ll
-bash: “ls: command not found
$ la
total 0
drwxr-xr-x 2 alneuman staff 68 Mar 17 12:18 .
drwxrwxrwx+ 70 alneuman staff 2380 Mar 17 12:18 ..
Have a look here at unix.stackexchange. Somebody had the same issue. Brave new unicode world ;)
Sourcetree allows us to launch a .sh script, which is called Custom action. I am going to register a .sh file to open file with Sublime text. Before doing it, I did a test and found something is weird. the owner of Sourcetree launcher is hello and the owner of Bash shell is also hello like:
choegyutaes-MacBook-Pro:MacOS hello$ pwd
/Applications/SourceTree.app/Contents/MacOS
choegyutaes-MacBook-Pro:MacOS hello$ ls -al
total 6752
drwxr-xr-x# 3 hello admin 102 Feb 4 2015 .
drwxr-xr-x# 10 hello admin 340 Aug 9 00:46 ..
-rwxr-xr-x# 1 hello admin 3456064 Feb 4 2015 SourceTree
But Sourcetree script launcher does not have the exported PATH from ~/.bash_profile.
choegyutaes-MacBook-Pro:scripts hello$ cat ~/.bash_profile
#MAVEN
export M2_HOME=/usr/bin/apache-maven-3.3.3
export M2=$M2_HOME/bin
export PATH=$M2:$PATH
#Mysql
export MYSQL=/usr/local/mysql/bin
export PATH=$MYSQL:$PATH
#bash history timestamp
export HISTTIMEFORMAT="%d/%m/%y %T "
#Sublime text
export SUBLIME=/Applications/Sublime\ Text.app/Contents/SharedSupport/bin
export PATH=$SUBLIME:$PATH
my shell script (sublime.sh)
#!/bin/bash
whoami
echo $PATH
sleep 3
lanuch script from Bash shell (iTerm)
choegyutaes-MacBook-Pro:scripts hello$ ./sublime.sh
hello
/Applications/Sublime Text.app/Contents/SharedSupport/bin:/usr/local/mysql/bin:/usr/bin/apache-maven-3.3.3/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
launch script from Sourcetree.
as yon can see, the result of echo $PATH is different, but the result of whoami is the same. I think this would not a problem with Sourcetree. It occurs from my unfamiliarance with *nix system and environment variable. Why does not Sourcetree script launcher know the path to Sublime text?
.bash_profile is just for running a bash shell in a terminal.
You are probably running SourceTree from a shortcut or menu.
If you run SourceTree from your bash prompt you should find that it picks up the environment set and exported by .bash_profile.
Assuming that's it, then you need your short-cut or menu to have the same - I don't know OS-X - but there must be some means of setting the environment for an entire user context (i.e. for any process started under a user session, graphical from a menu, or a bash shell, or whatever.)
I've been trying to work on opening/executing MATLAB from bash (I'm using Terminal, specifically). However, despite numerous attempts at troubleshooting, I have been unable to do it.
Running the "matlab" command gives me the error:
-bash: matlab: command not found
A cursory Google search suggested it could be an issue of my local bin, but my bin looks like:
/usr/local/bin:
total used in directory 16 available 208047788
drwxr-xr-x 4 alifarhat wheel 136 Jul 22 11:30 .
drwxr-xr-x 3 alifarhat wheel 102 Jan 22 01:56 ..
lrwxr-xr-x 1 alifarhat wheel 29 Jul 22 11:30 matlab -> /usr/local/matlab6/bin/matlab
lrwxr-xr-x 1 alifarhat wheel 26 Jul 22 11:30 mex -> /usr/local/matlab6/bin/mex
Which seems to indicate that matlab is talking to the bin.
If it helps, when I cd into /usr/local and then ls, the only directory/item in there at all is "bin". Could this have something to do with it? How can I fix it if it does?
It seems like PATH issues. Is /usr/local/bin in your $PATH?
Try
~$ echo $PATH
What do you see?
If /usr/local/bin is not part of your $PATH you can add it:
~$ export PATH=/usr/local/bin:$PATH
Then try and run matlab from shell
EDIT:
Based on these comments it seems like matlab executable is not located at /usr/local/matlab6/bin. Therefore, you can either
Add /Applications/MATLAB_R2014a.app/bin/ to path:
~$ export PATH=/Applications/MATLAB_R2014a.app/bin:$PATH
or
Replace the broken symbolic links in /usr/local/bin (you might need root privileges for this). See this thread for more details.
Once you are in the correct directory, you should execute the command:
./matlab
instead of just typing matlab.