Error open: command not found during command script in mac - bash

I built a new script that set env and open intellij:
#! /bin/bash
launchctl setenv USERNAM ttt, PASSWORD
1234
#! /bin/bash

open -a "IntelliJ IDEA"
when i ran it on terminal separately it works but when i run on my script im getting this error "open: command not found"
i'm using mac osx
thanks

solution:
it was actually an extra space or end of line I made by mistake...

I'm not sure what launchctl setenv ... does, and how it affects your current shell, but I think your script can be more simply written:
#! /bin/bash
export USERNAM="ttt"
export PASSWORD="1234"
open -a "IntelliJ IDEA"
or
#! /bin/bash
env USERNAM="ttt" PASSWORD="1234" open -a "IntelliJ IDEA"

Related

Run .bash_profile when I open a new terminal

When I open a new terminal, I have to run :
source ~/.bash_profile every time...
How can I automate this ?
I have read lot of thing on internet but I don't find any clear response.
Thanks
FYI : when I run
echo $SHELL
I get /bin/zsh
As your shell is zsh, it loads .zshrc file when terminal (in login mode) started.
Either you have to change your shell to be /bin/bash or copy .bash_profile into .zshrc
to change the shell:
chsh -s /bin/bash
to copy profile:
cp ~/.bash_profile ~/.zshrc
# or create a symlink
ln -s ~/.bash_profile ~/.zshrc
As zsh terminal load .zshrc when started.
So we can loading .bash_profile actively by
echo 'source ~/.bash_profile' >> ~/.zshrc

Exporting ROS Master URI from shell script

I am trying to export ROS_MASTER_URI from a shell script and then launch roscore. In my .sh file I have:
roxterm --tab -e $SHELL -c "cd $CATKIN_WS; $srcdevel; export ROS_MASTER_URI='http://locahost:1234'; roscore -p 1234"
When I do this, however, I get the following error in the roscore tab:
WARNING: ROS_MASTER_URI [http://locahost:1234] host is not set to this machine.
When I echo the ROS_MASTER_URI in this tab, it says that it is localhost:1234, which is correct. When I manually execute these commands, it works correctly and roscore launches without any issues. I am not sure why it does not work when launched from a bash file.
It was just a typo- missed the l in localhost. All working now.

Xubuntu, make a launcher for a .sh

I use Xubuntu with gnome-terminal.
I need to launch a sh script (restart.sh) on the pc startup.
The .sh file is in this directory: "/home/stark/Desktop/Tracking/Release/5600/"
I created a launcher like this:
[Desktop Entry]
Name=My GUI App
Exec=gnome-terminal -x sh -c "/home/stark/Desktop/Tracking/Release/5600/restart.sh"
Icon=/path/to/you/icon.svg
Terminal=true
Type=Application
StartupNotify=true
Name[en_US]=Intel5600
Comment=
Path=
What's wrong? Thank you!
EDIT:
This is the bash file:
#!/bin/bash
gnome-terminal -x sh -c 'python3 main00.py'
If I start it from its folder it works (if in a terminal I type: ./restart.sh), but from the launcher it doesn't work.
I tried to set terminal=false, but nothing changes.
add an #reboot cron task:
Running crontab -e will allow you to edit your cron.
Adding a line like this to it:
#reboot /path/to/script
will execute that script once your computer boots up.
vi /etc/rc.local
with content like the following:
# This script is executed at the end of each multiuser runlevel
/path/to/my/script.sh || exit 1 # Added by me
exit 0

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.

Open gnome terminal programmatically and execute commands after bashrc was executed

I try to build a little script to start my development environment. For that task I try to open a gnome terminal with several tabs where automatically the rails server and autotest is started.
But
gnome-terminal --tab -e "rails server" --tab --tab
does not work ("error creating the child process").
Also
gnome-terminal --tab -e "bash -c \"rails server\"" --tab --tab`
does not work.
Any suggestions how to solve that problem?
Here is a nice trick we worked out at Superuser
Add a eval "$BASH_POST_RC" to the end of your .bashrc
Set the BASH_POST_RC environment variable for each tab to that command you like to execute, e.g.: gnome-terminal --working-directory="/home/zardoz/projects/my_rails_app" --tab -e 'bash -c "export BASH_POST_RC=\"rails server\"; exec bash"' --tab -e 'bash -c "export BASH_POST_RC=\"autotest\"; exec bash"'
#Gilles: Thanks for that solution!
Stab in the dark: create shell scripts for each command you want to run in a tab, make them executable, and invoke them by absolute path, e.g. put this in /home/zardoz/bin/railsstart
#! /bin/sh
exec rails server
chmod +x it, and then do
gnome-terminal --tab -e /home/zardoz/bin/railsstart --tab --tab ...
If that doesn't work, the next thing I would try is sticking strace -f -o /tmp/trace.log on the beginning of the command, letting it fail, and then digging through trace.log to find out which system call actually failed and why (there'll be a tremendous amount of junk in there - read from the end backward and look for all-capitalized code phrases starting with E, like "ENOEXEC", "ENOENT", "EPERM", sort of thing.)
EDIT: Here's how you pull in all the .bashrc settings in one of these scripts:
#! /bin/bash
. ~/.bashrc
exec rails server
Caution: you may need to adjust your .bashrc so that it doesn't do certain things that only work in a "real" interactive shell session. Don't worry about this unless you get strange errors before rails starts.
I'm assuming the error arises because PATH is not set at the time gnome-terminal tries to run rails.
Why not use the full path to the rails server, or create a script that sets the PATH variable?
Already replied, but just in case, check out this gem that automates the terminal on KDE, OSX and Gnome desktops.
for ubuntu 16.04
press Ctr+Shift+T
this will open a new tab in the same window. additionally a button for adding more tabs will appear next to the right most tab.

Resources