Tag Info

Hot answers tagged

62

It isn't a shebang, it is just a script that gets run by the default shell. The shell executes the first line //usr/bin/env go run $0 $@ ; exit which causes go to be invoked with the name of this file, so the result is that this file is run as a go script and then the shell exits without looking at the rest of the file. But why start with // instead of ...


62

From your other questions I take it you're using OS X. The default HFS+ filesystem on OS X is case-insensitive: you can't have two files called "abc" and "ABC" in the same directory, and trying to access either name will get to the same file. The same thing can happen under Cygwin, or with case-insensitive filesystems (like FAT32 or ciopfs) anywhere. ...


18

In bash, . and source are synonyms. Looking into bash source code, file builtin/source.def, you can see . and source use the same internal function source_builtin: $BUILTIN source $FUNCTION source_builtin $SHORT_DOC source filename [arguments] Execute commands from a file in the current shell. Read and execute commands from FILENAME in the current shell. ...


17

maxproc and maxfiles might go unlimited in previous OSX versions, however in Mavericks, they have an artificial maximum value. To increase default maxproc and maxfiles in launchctl, append the following lines to /etc/launchd.conf (create if it does not yet exist): limit maxfiles 16384 16384 limit maxproc 2048 2048 Be aware: those numbers are about as ...


15

Because builtins are part of the shell. Any bugs or history they have are bugs and history of the shell itself. They are not independent commands and don't exist outside the shell they are built in. The equivalent, for bash at least, is the help command. For example: $ help while while: while COMMANDS; do COMMANDS; done Execute commands as long as a ...


12

This can be do the same thing with purge: sync && echo 3 > /proc/sys/vm/drop_caches From man proc: /proc/sys/vm/drop_caches (since Linux 2.6.16) Writing to this file causes the kernel to drop clean caches, dentries and inodes from memory, causing that memory to become free. To free ...


12

The addition of keys to the agent is transient. They last only so long as the agent is running. If you kill it or restart your computer they're lost until you re-add them again. From the ssh-agent man page: excerpt #1 ssh-agent is a program to hold private keys used for public key authentication (RSA, DSA, ECDSA). The idea is that ssh-agent is started ...


11

Looking at the source code for mv, http://www.opensource.apple.com/source/file_cmds/file_cmds-220.7/mv/mv.c : /* * If rename fails because we're trying to cross devices, and * it's a regular file, do the copy internally; otherwise, use * cp and rm. */ if (lstat(from, &sb)) { warn("%s", from); return (1); } return (S_ISREG(sb.st_mode) ? ...


10

Moving a file to the location of an already existing file replaces the existing file. In this case the /dev/null device file is replaced, just as any normal file would be. To avoid this use the -i (interactive, warns before overwriting) or -n (no clober) option for mv. /dev/null only performs its special function as a bit-bucket then the device is opened as ...


9

On OS/X like on many systems (BSDs, Solaris, AIX, IRIX...), the functionality of GNU tac is available in tail with the -r option. So no need to install GNU tac: tail -r the-file


9

This is POSIX's definition of .dot: The shell shall execute commands from the file in the current environment. If file does not contain a /<slash>, the shell shall use the search path specified by $PATH to find the directory containing file. Unlike normal command search, however, the file searched for by the .dot utility need not be ...


9

This is what Bash while loops do: while /path/to/application.app do : done It will run the application, and if it terminates successfully run the body of the loop. : is the shell's no-op command (the loop has to have a body, so that's what we put there); after that it goes back to the top and runs the program again. If it fails, the loop stops running ...


8

Yes: Install Homebrew brew install coreutils ln -s /usr/local/bin/gtac /usr/local/bin/tac or use MacPorts to install coreutils in a similar way.


8

Umm, because you overwrite the special file with normal one? What did you expect to happen? dev/null is not a directory, it is a file pointing to a null device. When you mv something to it, you delete the original and replace it with whatever you moved: $ file /dev/null /dev/null: character special $ sudo mv file /dev/null $ file /dev/null /dev/null: ...


8

The main reason that X terminal applications run non-login shells by default is that in the beginning of time, your .Xsession would have run the .profile to set up your initial login items. Then, since that was all set up already, terminal apps didn't need to run it, they could run the .bashrc. Discussion of why this would matter is at ...


8

As suggested in the comments, OS X primary is a real Unix since it is certified by The Open Group (owner of the UNIX™ trademark), allowing it to legally claim itself to be UNIX. Primary requirement for being UNIX certified is being conforming to the POSIX standard(s). Second one is being able to pay The Open Group the certification process. I think the ...


8

The difference is that Windows implicitly has . in the path, which is something it inherited from DOS, which always was a single user system. Mac OS X is build on Unix, which is a multi user system. And for security reasons it does not have . implicitly in the path. When . is not in the path, then to run a command in the current directory, one has to ...


8

STDOUT and STDERR don't have colors. What has color is your terminal (emulator); it has one foreground (and one background color) set at a time. It should also be noted that STDOUT and STDERR are not singular -- they're per process output streams. There is no global STDOUT that applies to all programs. These streams are routed to your terminal, but they ...


8

If you don't want to be challenged every time for your password then I'd recommend setting it to NOPASSWD in your /etc/sudoers file rather than hardcode your password in your logins. At least this way your primary login's password will remain intact and not be completely exposed in your .bashrc. To make this change run the command sudo visudo, and change ...


8

It runs because by default executable file is assumed to be /bin/sh script. I.e. if you didn't specify any particular shell - it is #!/bin/sh. The // is just ignored in paths - you can consider is at as single '/'. So you can consider that you have shell script with first line: /usr/bin/env go run $0 $@ ; exit What does this line do? It runs 'env' with ...


7

On OSX, the @ symbol indicates that the file has extended attributes. You can see them using xattr -l, or ls -@. From man 1 ls on OSX 10.9: If the file or directory has extended attributes, the permissions field printed by the -l option is followed by a @ character.


7

With zsh on terminals that support 16 colors or more à la xterm: preexec() printf '\e[90m' # set foreground color to grey before running # the command precmd() printf '\e[m' # reset the foreground color before issuing the # next prompt. Note that commands may change the terminal's foreground color ...


7

You can remove the first 12 lines with: tail -n +12 Some implementations of head like GNU head support: head -n -12 but that's not standard. tail -r file | tail -n +12 | tail -r would work on those systems that have tail -r (see also GNU tac) but is sub-optimal. Where n is 1: sed '$d' file You can also do: sed '$d' file | sed '$d' to remove 2 ...


6

For the shebang line, use: #!/usr/bin/env perl env will search the PATH at execute the first perl that it finds. If you want to specify any options for perl, just add them to the end of the line above. If more than one perl is installed, env will run the first one it finds in PATH.


6

Or, you can have sh take care of it for you: #!/bin/sh exec perl -x "$0" "$@" #!/usr/bin/perl ... Yes, that's sh and Perl all in one file. From man perlrun: -x tells Perl that the program is embedded in a larger chunk of unrelated text, such as in a mail message. Leading garbage will be discarded until the first ...


5

It seems you are asking two or three questions. To use ssh to tunnel, I advise you start a non-interactive session ssh -C2qTnN -D 8080 user@IP That will put the ssh tunnel in the background. Use the proxy: You then configure your browser or system settings to use the proxy on localhost port 8080. Stop using the proxy: You then re-configure your system ...


5

You should find that get volume settings will return an object containing among other things the output volume and the alert volume. So for example you could do this to retrieve the entire object: osascript -e 'get volume settings' or rather maybe this to grab just the output volume (e.g. rather than the alert volume): osascript -e 'set ovol to output ...


5

basename operates on its command line argument, it doesn't read from standard input. You don't need to call the basename utility, and you'd better not: all it would do is strip off the part before the last /, and it would be slow to call an external command for each entry, you can use a text processing utility instead. find ~ -type f | sed 's!.*/!!' | sort ...


5

The way it's supposed work is that, at the point when you get a shell prompt, both .profile and .bashrc have been run. The specific details of how you get to that point are of secondary relevance, but if either of the files didn't get run at all, you'd have a shell with incomplete settings. The reason terminal emulators on Linux (and other X-based systems) ...


5

Your problem is that you try to enter C code into a shell prompt, this doesn't work for obvious reasons. You could either put it into a correct C file, compile it and get a valid binary you could execute: #include <linux/kd.h> #include <sys/ioctl.h> #include <fcntl.h> #include <unistd.h> #include <err.h> #include ...



Only top voted, non community-wiki answers of a minimum length are eligible