I need to get the home directory in my shell script so my coworkers can run it. What my shell does is really simple, it only copy some directories to another. I've used:
$HOME,
$(whoami)
even this:
ABSPATH=$(cd "$(dirname "$0")"; pwd),
but when I use the variable like this:
DIR= $ABSPATH/folder/afolder/bfolder/
and run it I receive this:
/Users/theUser/Desktop/FusionTest.command: line 14: /Users/theUser/Desktop/folder/afolder/bfolder: is a directory
Copying to usage: cp [-R [-H | -L | -P]] [-fi | -n] [-apvX] source_file target_file cp [-R [-H | -L | -P]] [-fi | -n] [-apvX] source_file ... target_directory logout
[Process completed]
I'm using the command cp -r to copy all files and directories.
Whay I am missing? or how can I do this??
Here are a couple of quick tricks for moving around in your Mac's file system. If you type cd and press the Return key—with no directory specified—you'll go back to your Home folder. (You can also type cd ~ to go there.)
You can go back to the parent directory of any current directory by using the command cd .. , as the full path of the current working directory is understood by Bash . You can also go back to your home directory (e.g. /users/jpalomino ) at any time using the command cd ~ (the character known as the tilde).
Home. Your home folder is named with your username and has folders for your desktop files, downloads, pictures, documents, movies, music and any public files. You can create folders in your home folder.
The Linux home directory is a directory for a particular user of the system and consists of individual files. It is also referred to as the login directory. This is the first place that occurs after logging into a Linux system. It is automatically created as "/home" for each user in the directory'.
As the error message implies -r
is the incorrect flag for recursive copying. The flag you want is -R
(flags are case-sensitive). As for the home directory, $HOME
should always work.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With