Move .app with .command on Mac - macos

I'm trying to make a command to move an app I made to the applications directory without having to make a full installer. Right now this is the command I'm running with the proper permissions (I used chmod +x install.command):
mv My\ Application.app /Applications/
This gives me the output
mv: My Application.app: No such file or directory
logout
If I just run this command in the terminal it works, any idea what's going on?
EDIT:
I can't seem to manipulate "My Application.app" at all from the .command file. I tried running just rm -r "My Application.app" and it still can't seem to find the directory. The .command is in the same directory as "My Application.app"

If you aren't running this script from the dir that holds "My Application.app"
then you need to have the full path to "My Application.app".
Also you should try it with quotes.
mv "/path/to/My Application.app" /Applications/

.command files don't run with their current working directory set to the directory they are in, which is why it doesn't work; it's running in your home directory. You'll need to use either an absolute path, or a path relative to your home directory, not relative to the directory of the .command file.

Related

Command not found in ssh but is in direcory

I am using an ssh account that connects to an external server, i have downloaded through guix some software like samtools and bedtools but when i try to use them in my directory it gives me this error:
-bash: samtools: command not found
In my direcory, however, there is the directry guix.profile and if I go into the bin folder of this, I have everything I downloaded.
What am I doing wrong?
Thank you
enter image description here
To run a file from the shell you need two things:
The shell must find the file
Being in the same directory does not enable the shell to find the file. You have to either supply an absolute or relative path the file, or have the directory in your PATH environment variable
In simplest terms this means instead of
$ samtools
try
$ ./samtools
The relative path tells the shell it wants that file
To run it from another directory, either use the whole absolute path, e.g. /home/yourname/samtools , or move the file into a directory that is on your $PATH
The file needs to be executable
If the file is not executable you will need
$ chmod +x ./samtools

-bash: cd: /tensorflow1: No such file or directory in ubuntu, but the file is there

I am using ubuntu 16.04 and created a virtual environment called 'tensorflow1' as shown above. I am using putty to access a machine remotely. So I was trying to change directory by typing "cd /tensorflow1/models/research" but it says "-bash: cd: /tensorflow1: No such file or directory" in ubuntu, but the file is there. I typed "ls" and it also shows the file. Why is it so?
When you type ls you see the content of the current directory. When you type cd /tensorflow1 you're trying to enter a directory tensorflow1 at the root (/) of the filesystem and the directory is certainly not there. You just need
cd tensorflow1/models/research
to enter a subdirectory of the current directory. Or
cd ./tensorflow1/models/research
because . means "the current directory".
You probably want cd ./tensorflow1/models/research or just cd tensorflow1/models/research.
Read about root directory, home directory, working directory then about path_resolution(7)

No such file or directory - terminal won't recognize directory

When I simply try to cd into a directory on my desktop (cd command + drag folder to terminal to generate file path) I get an error that says "No such file or directory" however, as you can see in the screenshot the folder is there on my desktop. What could be the problem? Thanks.
Seems you have to put a space after the cd command, otherwise the Desktop is available with ~/Desktop on macos shell

Bash script not working even when in my PATH

I created a simple bash script. The script works just fine.
When I run echo $PATH this prints my paths, I have:
/usr/local/sbin:/usr/local/bin/:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin
So i moved my script to /usr/local/bin and ran chmod +x mybash.sh. I've even chmod 0777 mybash.sh
Now, when I run ./mybash.sh I just get the "No such file or directory"
Why is this happening and where's the best place to put my scripts
Once the script is in your path, you can run it just with the filename: mybash.sh rather than the path to the file: ./mybash.sh
./mybash.sh means run mybash.sh from the current folder. If you've moved mybash.sh to /usr/local/bin, then it's no longer in ./ (your current folder), so it can't find it.
Either move to /usr/local/bin to run it using ./mybash.sh or just use mybash.sh from any folder once you've moved it into a path folder.

Whats different when you executable a scripts in OSX?

I have a question I have been trying to fix for a while. I want to understand what's the difference between starting a script from the command line and making it executable and then running it from the Finder.
Because this is what I am experiencing;
I have a simple script called trash-files which contains this command:
trash ~/Downloads/*
When I run from the terminal it works as expected; however if I doubleclick the shell script in the finder I see this:
/Users/xx/Desktop/trash-files: line 1: trash: command not found
I hope anyone can tell me why this doesn't work as expected
trash is not a standard command in OS X. Is it something defined in your ~/.profile or a similar file? If so, these are not run for non-login shells, such as those created to run a script.
If you're using homebrew, you could run
brew install trash
which would install the necessary scripts to have the trash command work in the way you're expecting.
There is a folder in your home folder location called
.Trash
The "dot" in front of the folder name makes it hidden while searching for it in finder. You'll have to use Terminal to execute the following command:
cd ~/
ls -la
This will change the directory to the current logged in users home folder, then second command will list files and show hidden files. You can then run:
rm .Trash/*
This will remove everything inside the Trashcan on the dock.
So open TextEdit from the /Applications folder, go to "Format" and make it "Plain Text". Paste in the two lines below.
#!/bin/sh
rm ~/.Trash/*
Save the file as "emptyTrash.sh" (uncheck use txt extension). Save it to your Desktop or wherever you'd like. Then open Terminal, cd (change directory) to where the files is and run this command to make the script executable:
chmod +x emptyTrash.sh
Then you can execute the script by cd (changing directory) to path where the script is, and run:
./emptyTrash.sh
That's it.

Resources