Laravel Homestead Per Project Install Bash Aliases Commands Not Found - laravel

I've created a per project install of Homestead. I've included after.sh (in the root directory) to provision other packages like RethinkDB with no issues, but the aliases file (also in root directory) though appearing in the VM as ~/.bash_aliases isn't running any of the aliases when I'm type them in. So for example these aliases:
alias artisan='php artisan'
alias autoload='composer dump-autoload'
In the command prompt as:
artisan migrate:refresh --seed
autoload
Throw these errors:
Could not open input file: artisan
autoload: command not found
This happens for any of the aliases I try. I've checked that ~/.bash_aliases (or /home/vagrant/.bash_aliases) exists using nano, and it is definitely a copy of aliases. Just none of the commands are being used as if it doesn't exist or as if the file though in the right spot is inaccessible.
Anyone know why? or how to fix this? It's amazing how annoying not being able to use the aliases I typically would use locally, or on global install of Homestead when using this VM.
UPDATE
I noticed I get a list of command not found errors when I SSH into the VM that equal the number of aliases I've included. The same list appears if I run source ~/.bash_aliases. For complete clarity .bash_aliases is located in /home/vagrant next to the mapped source folder /home/vagrant/app, and the output from SSHing into the VM, and the associated aliases file are included:
SSH into VM
$ vagrant ssh
Welcome to Ubuntu 14.04.3 LTS (GNU/Linux 3.19.0-25-generic x86_64)
* Documentation: https://help.ubuntu.com/
Last login: Mon Feb 15 00:37:39 2016 from 10.0.2.2
: command not found
: command not found
: command not found
: command not found
: command not found
: command not found
: command not found
: command not found
: command not found
: command not found
vagrant#app:~$
Aliases File
# Homestead --------------------------------------------------------------------
alias ..="cd .."
alias ...="cd ../.."
alias h='cd ~'
alias c='clear'
alias phpspec='vendor/bin/phpspec'
alias phpunit='vendor/bin/phpunit'
# Laravel ----------------------------------------------------------------------
# Access Artisan when within project folder
alias artisan='php artisan'
# Access Tinker when within project folder
alias tinker="php artisan tinker --env=local"
# Composer --------------------------------------------------------------------
alias autoload='composer dump-autoload'
# App -------------------------------------------------------------------------
alias app="cd app"
After.sh File
#!/usr/bin/env bash
#
# Install RethinkDB on Ubuntu
# #see https://www.rethinkdb.com/docs/install/ubuntu/
#
# Add RethinkDB repository and install
source /etc/lsb-release && echo "deb http://download.rethinkdb.com/apt $DISTRIB_CODENAME main" | sudo tee /etc/apt/sources.list.d/rethinkdb.list
wget -qO- https://download.rethinkdb.com/apt/pubkey.gpg | sudo apt-key add -
sudo apt-get update
sudo apt-get install -y rethinkdb
# Setup RethinkDB as a service using default configuration file
#sudo cp /etc/rethinkdb/default.conf.sample /etc/rethinkdb/instances.d/instance1.conf
#sudo vim /etc/rethinkdb/instances.d/instance1.conf
#sudo /etc/init.d/rethinkdb restart
# Setup RethinkDB as a service by copying the custom configuration file
sudo cp /home/vagrant/app/rethinkdb.conf /etc/rethinkdb/instances.d/instance1.conf
sudo /etc/init.d/rethinkdb restart
UPDATE 2
Nano output of .bash_aliases, which looks like my aliases file, but the output after this of alias truncates the first letter of the aliases.
# Homestead ----------------------------------------------------------------------
alias ..="cd .."
alias ...="cd ../.."
alias h='cd ~'
alias c='clear'
alias phpspec='vendor/bin/phpspec'
alias phpunit='vendor/bin/phpunit'
# Laravel ----------------------------------------------------------------------
# Access Artisan when within project folder
alias artisan='php artisan'
# Access Tinker when within project folder
alias tinker="php artisan tinker --env=local"
# Composer --------------------------------------------------------------------
alias autoload='composer dump-autoload'
Output from just typing alias into terminal:
vagrant#app:~$ alias
'lias ..='cd ..
'lias ...='cd ../..
alias alert='notify-send --urgency=low -i "$([ $? = 0 ] && echo terminal || echo error)" "$(history|tail -n1|sed -e '\''s/^\s*[0-9]\+\s*//;s/[;&|]\s*alert$//'\'')"'
'lias artisan='php artisan
'lias autoload='composer dump-autoload
'lias c='clear
alias egrep='egrep --color=auto'
alias fgrep='fgrep --color=auto'
alias grep='grep --color=auto'
'lias h='cd ~
alias l='ls -CF'
alias la='ls -A'
alias ll='ls -alF'
alias ls='ls --color=auto'
'lias phpspec='vendor/bin/phpspec
'lias phpunit='vendor/bin/phpunit
'lias tinker='php artisan tinker --env=local
FINAL SOLUTION
Thanks to #JoshRumbut for solving this issue, see below for his comments.
vagrant#app:~$ tr -d '\r' <~/.bash_aliases >~/tmp
vagrant#app:~$ mv ~/tmp ~/.bash_aliases
vagrant#app:~$ unalias -a
vagrant#app:~$ source .bash_aliases

Is bash configured to look in the .bash_aliases file?
What happens if you run source ~/.bash_aliases? Do they work then?
Edit: current theory is that a weird character, possibly the carriage return (\r) is embedded in the file somewhere, as in thus question: https://unix.stackexchange.com/questions/35642/why-are-these-aliases-failing

Related

How to use bash aliases in a non-interactive shell?

I am using Windows 10. I followed this tutorial on how to create bash aliases. I put the aliases in ~/.bashrc, and used source ~/.bashrc afterwards. When I tried to use one of the aliases, I get the following error:
$ docs
bash: docs: command not found
I opened a new PowerShell session, used bash, tried the alias and it still gave the same error. But it only worked when I tried it on Git Bash. From what I've researched, I was opening bash in a non-interactive shell. I tried the answer on this post and put shopt -s expand_aliases at the end of .bashrc, but it still wouldn't work. This is what my .bashrc looks like:
######## Aliases #######
# Git
alias gcl="git clone"
alias gco="git commit"
alias gcom="git commit -m"
alias gpus="git push"
alias gpul="git pull"
alias gbr="git branch"
alias gad="git add"
alias gre="git restore"
alias grest="git restore"
alias gsw="git switch"
alias gst="git status"
alias gcoam="git commit --amend"
alias gcoamne="git commit --amend --no-edit"
alias gcoamm="git commit --amend -m"
# Navigation
alias home="cd ~"
alias docs="cd ~/Documents"
alias labs="cd ~/Documents/VSCode"
alias open="code ."
################
shopt -s expand_aliases # allows aliases available in non-interactive shells
How do I make the bash aliases work in a non-interactive shell?
You have to turn on this feature:
shopt -s expand_aliases

ddev exec: command not found (.bash_aliases)

In a local ddev instance, I have added a few aliases and functions to .ddev/homeadditions/bash_aliases.
For example: alias ll="ls -lhA"
While ddev ssh and then ll will work, ddev exec ll returns
bash: ll: command not found
Failed to execute command ll: exit status 127
Why?
It's really about how bash works, not about how ddev works. The .bashrc (and thus .bash_aliases, which gets loaded by .bashrc) is only loaded by interactive shells (contexts like ddev ssh). Here'a an Stack Overflow answer on it: Why aliases in a non-interactive Bash shell do not work
ddev exec just does a bash -c "<your command>", and bash -c is noninteractive by design.
You might consider adding ddev custom web commands for things you can't live without.
A ddev ll custom command could work like this. Create a file named "ll" in .ddev/commands/web with the contents
#!/bin/bash
## Description: Run ls -l inside web container
## Usage: ll [flags] [arguments]
## Example: "ddev ll" or `ddev ll /tmp`
ls -l $#
Here's an example of my setup (actually, I have scripts more than just ll)
.ddev/docker-compose.env.yaml
version: '3.6'
services:
web:
environment:
- PROD_USER=foo
- PROD_SERVER=bar.com
- PROD_ROOT=path/to/root
- LOCAL_ROOT=that/path/to/root
- ASSET_DIRS=bi ba bu
.ddev/commands/web/sync_down_files
#!/bin/bash
# rsync prod assets to local
# download all assets
for directory in ${ASSET_DIRS} ; do
rsync -zra \
--delete \
--exclude='.env' \
${PROD_USER}#${PROD_SERVER}:/home/${PROD_USER}/${PROD_ROOT}/$directory \
${LOCAL_ROOT};
done
Now I do ddev sync_down_files and get all remote assets into the local site. Same for the db.

ZSH: command not found

I want to execute command gclient. I have already included its location in PATH. But I cannot directly execute it by command. Can someone tell me why?
~
❯ echo $PATH
/User/merle/depot_tools:/Users/merle/.nvm/versions/node/v11.10.0/bin:/usr/local/opt/mysql#5.5/bin:/Library/Frameworks/Python.framework/Versions/3.5/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/TeX/texbin:/opt/X11/bin:/Library/Frameworks/Mono.framework/Versions/Current/Commands
~
❯ ls depot_tools | grep gclient
README.gclient.md
annotated_gclient.py
gclient
gclient-new-workdir.py
gclient.bat
gclient.py
gclient_completion.sh
gclient_eval.py
gclient_paths.py
gclient_scm.py
gclient_utils.py
~
❯ gclient
zsh: command not found: gclient
~
❯ cd depot_tools
~/depot_tools master
❯ ./gclient
Usage: gclient.py <command> [options]
Meta checkout dependency manager for Git.
Commands are:.......
Take another look at your path:
export PATH=/User/merle/depot_tools:/Users/merle/...
Does your system contain just 1 User or multiple Users???
It should read:
export PATH=/Users/merle/depot_tools:/Users/merle/...
i think you may forget
source ~/.nvm/nvm.sh
if you want automatically load it ,there are two ways
open ~/.zshrc
1.add
source ~/.nvm/nvm.sh
2.or add
export NVM_DIR="/Users/YOUR_USER_NAME(you need use you user name)/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" # This loads nvm
hope this can help you
ZSH: command not found
The Problem was .zshrc, it was missing.
the solution which worked for me :
You have to create a .zshrc file.
to create use "vim .zshrc" command then insurt your path "export PATH="$PATH:pwd/flutter/bin"
save and completely exit your terminal completely. install gem cocoa pods then accept the license. you are good to go.

Mac Terminal process ends and outputs [Process completed] when launched

When I launch the Terminal app on Mac, the process will end and output the following:
Last login: Wed Aug 6 15:53:58 on ttys003
[Process completed]
This started happening when terminal froze and I restarted it. From then on, this is the message that is displayed.
I can change the Shell to bin/sh in Terminal's preferences, but this prevents me from using my .bash_profile script.
Does anyone have any ideas or suggestions on how to fix this?
Thanks!
PS Here's my .bash_profile. I tried commenting it out and running Terminal and it still didn't work, but here is per request.
export PATH="/usr/local/mysql/bin:$PATH"
##
# Your previous /Users/mjmitchener/.bash_profile file was backed up as /Users/mjmitchener/.bash_profile.macports-saved_2013-05-06_at_09:58:31
##
# MacPorts Installer addition on 2013-05-06_at_09:58:31: adding an appropriate PATH variable for use with MacPorts.
export PATH="/opt/local/bin:/opt/local/sbin:$PATH"
# Finished adapting your PATH environment variable for use with MacPorts.
### Added by the Heroku Toolbelt
export PATH="/usr/local/heroku/bin:$PATH"
### Composer Vendor Paths
export PATH="~/.composer/vendor/bin:$PATH"
### Bin Paths
export PATH="bin:$PATH"
### Vendor Paths
export PATH="vendor/bin:$PATH"
### Aliases
#
# Directories
alias partways='cd ~/Sites/projects/PartWays/'
alias trks='cd ~/Sites/projects/ThingsRichKidsSay/'
alias forrest='cd ~/Sites/projects/rest-client/workbench/omniphx/forrest/'
alias blog='cd ~/Sites/projects/blog'
alias tinynews='cd ~/Sites/projects/tinynews'
# Laravel Commands
alias art='php artisan'
alias l4project=''
# Generator Stuff
alias g:m="php artisan generate:model"
alias g:c="php artisan generate:controller"
alias g:v="php artisan generate:view"
alias g:s="php artisan generate:seed"
alias g:mig="php artisan generate:migration"
alias g:r="php artisan generate:resource"
# Node scripts
alias node_serve='node ./scripts/web-server.js'
#Git aliases
alias ggraph='git log --oneline --all --graph --decorate'
alias ga='git add'
alias gaa='git add .'
alias gau='git add -u'
alias gco='git checkout'
alias gst='git status'
alias gc='git commit'
alias gcm='git commit -m'
alias gca='git commit -a'
alias gcam='git commit -am'
alias gls='git ls-tree HEAD'
#PHPUnit
#Vagrant
alias vm='ssh vagrant#127.0.0.1 -p 2222'
#Sqlite3
alias db='sqlite3 app/database/production.sqlite'
Old thread but still relevant. It seems the only way to fix this without having to do workarounds that cause other issues, is to reinstall the OS. Its been a common issue since 2000.
By trying above steps you will solve this problem.
Delete node module of the project.
npm install
cd ios(if ios is configured)
now run your app.

How do I run a shell script without using "sh" or "bash" commands?

I have a shell script which I want to run without using the "sh" or "bash" commands. For example:
Instead of: sh script.sh
I want to use: script.sh
How can I do this?
P.S. (i) I don't use shell script much and I tried reading about aliases, but I did not understand how to use them.
(ii) I also read about linking the script with another file in the PATH variables. I am using my university server and I don't have permissions to create a file in those locations.
Add a "shebang" at the top of your file:
#!/bin/bash
And make your file executable (chmod +x script.sh).
Finally, modify your path to add the directory where your script is located:
export PATH=$PATH:/appropriate/directory
(typically, you want $HOME/bin for storing your own scripts)
These are the prerequisites of directly using the script name:
Add the shebang line (#!/bin/bash) at the very top.
Use chmod u+x scriptname to make the script executable (where scriptname is the name of your script).
Place the script under /usr/local/bin folder.
Note: I suggest placing it under /usr/local/bin because most likely that path will be already added to your PATH variable.
Run the script using just its name, scriptname.
If you don't have access to /usr/local/bin then do the following:
Create a folder in your home directory and call it bin.
Do ls -lA on your home directory, to identify the start-up script your shell is using. It should be either .profile or .bashrc.
Once you have identified the start up script, add the following line:
PATH="$PATH:$HOME/bin"
Once added, source your start-up script or log out and log back in.
To source, put . followed by a space and then your start-up script name, e.g. . .profile or . .bashrc
Run the script using just its name, scriptname.
Just make sure it is executable, using chmod +x. By default, the current directory is not on your PATH, so you will need to execute it as ./script.sh - or otherwise reference it by a qualified path. Alternatively, if you truly need just script.sh, you would need to add it to your PATH. (You may not have access to modify the system path, but you can almost certainly modify the PATH of your own current environment.) This also assumes that your script starts with something like #!/bin/sh.
You could also still use an alias, which is not really related to shell scripting but just the shell, and is simple as:
alias script.sh='sh script.sh'
Which would allow you to use just simply script.sh (literally - this won't work for any other *.sh file) instead of sh script.sh.
In this example the file will be called myShell
First of all we will need to make this file we can just start off by typing the following:
sudo nano myShell
Notice we didn't put the .sh extension?
That's because when we run it from the terminal we will only need to type myShell in order to run our command!
Now, in nano the top line MUST be #!/bin/bash then you may leave a new line before continuing.
For demonstration I will add a basic Hello World! response
So, I type the following:
echo Hello World!
After that my example should look like this:
#!/bin/bash
echo Hello World!
Now save the file and then run this command:
chmod +x myShell
Now we have made the file executable we can move it to /usr/bin/ by using the following command:
sudo cp myShell /usr/bin/
Congrats! Our command is now done! In the terminal we can type myShell and it should say Hello World!
You have to enable the executable bit for the program.
chmod +x script.sh
Then you can use ./script.sh
You can add the folder to the PATH in your .bashrc file (located in your home directory).
Add this line to the end of the file:
export PATH=$PATH:/your/folder/here
You can type sudo install (name of script) /usr/local/bin/(what you want to type to execute said script)
ex: sudo install quickcommit.sh /usr/local/bin/quickcommit
enter password
now can run without .sh and in any directory
Add . (current directory) to your PATH variable.
You can do this by editing your .profile file.
put following line in your .profile file
PATH=$PATH:.
Just make sure to add Shebang (#!/bin/bash) line at the starting of your script and make the script executable(using chmod +x <File Name>).
Here is my backup script that will give you the idea and the automation:
Server: Ubuntu 16.04
PHP: 7.0
Apache2, Mysql etc...
# Make Shell Backup Script - Bash Backup Script
nano /home/user/bash/backupscript.sh
#!/bin/bash
# Backup All Start
mkdir /home/user/backup/$(date +"%Y-%m-%d")
sudo zip -ry /home/user/backup/$(date +"%Y-%m-%d")/etc_rest.zip /etc -x "*apache2*" -x "*php*" -x "*mysql*"
sudo zip -ry /home/user/backup/$(date +"%Y-%m-%d")/etc_apache2.zip /etc/apache2
sudo zip -ry /home/user/backup/$(date +"%Y-%m-%d")/etc_php.zip /etc/php
sudo zip -ry /home/user/backup/$(date +"%Y-%m-%d")/etc_mysql.zip /etc/mysql
sudo zip -ry /home/user/backup/$(date +"%Y-%m-%d")/var_www_rest.zip /var/www -x "*html*"
sudo zip -ry /home/user/backup/$(date +"%Y-%m-%d")/var_www_html.zip /var/www/html
sudo zip -ry /home/user/backup/$(date +"%Y-%m-%d")/home_user.zip /home/user -x "*backup*"
# Backup All End
echo "Backup Completed Successfully!"
echo "Location: /home/user/backup/$(date +"%Y-%m-%d")"
chmod +x /home/user/bash/backupscript.sh
sudo ln -s /home/user/bash/backupscript.sh /usr/bin/backupscript
change /home/user to your user directory and type: backupscript anywhere on terminal to run the script! (assuming that /usr/bin is in your path)
Enter "#!/bin/sh" before script.
Then save it as script.sh for example.
copy it to $HOME/bin or $HOME/usr/bin
The directory can be different on different linux distros but they end with 'bin' and are in home directory
cd $HOME/bin or $HOME/usr/bin
Type chmod 700 script.sh
And you can run it just by typing run.sh on terminal.
If it not work, try chmod +x run.sh instead of chmod 700 run.sh
Make any file as executable
Let's say you have an executable file called migrate_linux_amd64 and you want to run this file as a command like "migrate"
First test the executable file from the file location:
[oracle#localhost]$ ./migrate.linux-amd64
Usage: migrate OPTIONS COMMAND [arg...]
migrate [ -version | -help ]
Options:
-source Location of the migrations (driver://url)
-path Shorthand for -source=file://path
-database Run migrations against this database (driver://url)
-prefetch N Number of migrations to load in advance before executing (default 10)
-lock-timeout N Allow N seconds to acquire database lock (default 15)
-verbose Print verbose logging
-version Print version
-help Print usage
Commands:
goto V Migrate to version V
up [N] Apply all or N up migrations
down [N] Apply all or N down migrations
drop Drop everyting inside database
force V Set version V but don't run migration (ignores dirty state)
version Print current migration version
Make sure you have execute privileges on the file
-rwxr-xr-x 1 oracle oinstall 7473971 May 18 2017 migrate.linux-amd64
if not, run chmod +x migrate.linux-amd64
Then copy your file to /usr/local/bin. This directory is owned by root, use sudo or switch to root and perform the following operation
sudo cp migrate.linux-amd64 /usr/local/bin
sudo chown oracle:oracle /user/local/bin/migrate.linux.amd64
Then create a symbolic link like below
sudo ln /usr/local/bin/migrate.linux.amd64 /usr/local/bin/migrate
sudo chown oracle:oracle /usr/local/bin/migrate
Finally add /usr/local/bin to your path or user profile
export PATH = $PATH:/usr/local/bin
Then run the command as "migrate"
[oracle#localhost]$ migrate
Usage: migrate OPTIONS COMMAND [arg...]
migrate [ -version | -help ]
Options:
-source Location of the migrations (driver://url)
-path Shorthand for -source=file://path
-database Run migrations against this database (driver://url)
-prefetch N Number of migrations to load in advance before executing (default 10)
-lock-timeout N Allow N seconds to acquire database lock (default 15)
-verbose Print verbose logging
-version Print version
-help Print usage
Commands:
goto V Migrate to version V
up [N] Apply all or N up migrations
down [N] Apply all or N down migrations
drop Drop everyting inside database
force V Set version V but don't run migration (ignores dirty state)
version Print current migration version
Make the script file as executable by using file's properties
Create alias for the executable in ~/.bashrc. alias <alias namme> = <full script file path>'
refresh the user session to apply it. source ~/.bashrc
Just to add to what everyone suggested. Even with those solutions, the problem will persist if the user wants to execute the script as sudo
example:
chmod a+x /tmp/myscript.sh
sudo ln -s /tmp/myscript.sh /usr/local/bin/myscript
typing myscript would work but typing sudo myscript would return command not found.
As sudo you would have to still type sudo sh myscript or sudo bash myscript.
I can't think of a solution around this.
Just:
/path/to/file/my_script.sh

Resources