Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mac Shell script get home directory

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??

like image 644
Rafael Jimeno Avatar asked Jun 22 '12 18:06

Rafael Jimeno


People also ask

How do I get to the home directory on a Mac terminal?

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.)

How do I get to the home directory in bash?

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).

What is the directory home in Mac?

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.

What is home directory in shell?

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'.


1 Answers

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.

like image 171
You Avatar answered Sep 30 '22 17:09

You