0

I have no idea why it isn't working. Using MacOS and bash:

$ echo $SHELL
/bin/bash

Here is the content of the file ```.bash_profile``:

enter image description here

I would imagine that I'm using right file - How do I create a Bash alias? - and the right syntax...

UPDATE:

Tried also .bashrc enter image description here

When I tried to reload it: $ source ~/.bashrc /usr/bin/alias: line 4: builtin: alias: not a shell builtin

UPDATE:

Yes, it looks weird

$ type alias
alias is a shell builtin
$ source ~/.bashrc
/usr/bin/alias: line 4: builtin: alias: not a shell builtin
Community
  • 1
  • 1
Mars Robertson
  • 12,673
  • 11
  • 68
  • 89
  • 1
    when you type in `compgen -b` at your prompt, what do you see? [Is `alias` in the list of builtins](http://askubuntu.com/questions/445749/whats-the-difference-between-shell-builtin-and-shell-keyword)? – Michael Dautermann Feb 17 '17 at 14:20
  • You could also try `type alias`. – cdarke Feb 17 '17 at 14:56
  • `/usr/bin/alias` is a shell script, you could take a look at it to check there is nothing strange happening there. I suggest you check that you are running `bash`, `$SHELL` only tells you what the login shell was, not the current shell. For that just do `ps` (no parameters). Also check `$BASH_VERSION`. – cdarke Feb 17 '17 at 14:59
  • @MichaelDautermann ```$ compgen -b``` and the result (in new lines) is: ```. : [ alias``` – Mars Robertson Feb 18 '17 at 09:52
  • @cdarke ```$BASH_VERSION``` result: ```-bash: 3.2.57(1)-release: command not found``` – Mars Robertson Feb 18 '17 at 09:54
  • @cdarke ```type alias``` result: ```alias is a shell builtin``` – Mars Robertson Feb 18 '17 at 09:54
  • I don't know why this isn't working either (hidden characters? builtin disabled (as with `enable -n alias`?) but I'd suggest using a function instead anyhow. `p() { python -m SimpleHTTPServer "$@"; }` can be invoked the exact same way, but can be extended with conditional logic and other features that aliases can't use. – Charles Duffy Feb 19 '17 at 02:01
  • BTW, for most Unix-family systems, Panta is right that `~/.bashrc` is a better choice for aliases, as it's sourced on startup for all interactive shells, as opposed to login shells only. OTOH, I vaguely recall MacOS behaving a bit unusually, and that wouldn't cause the "not a shell builtin" behavior anyhow. – Charles Duffy Feb 19 '17 at 02:03
  • Hmm. A builtin disabled with `enable -n` does appear to still show up in `compgen -b`, so I think we have a plausible theory; the question is *why* someone would have edited your dotfiles to do that. – Charles Duffy Feb 19 '17 at 02:04
  • actually, waitaminute; `type alias` describing it as a builtin dashes that theory... unless the output differs between when your `~/.bashrc` is being running and when you're in your interactive shell. – Charles Duffy Feb 19 '17 at 02:06
  • I'd recommend -- strongly, *strongly* recommend -- running `set -x` before `source ~/.bashrc`, to log the exact commands as bash thinks it's running them; if there are hidden characters (making the actual command, say, `$'\ralias'` instead of `alias`), that could result in the behavior at hand. – Charles Duffy Feb 19 '17 at 02:08
  • @CharlesDuffy ```$ source ~/.bashrc``` ➡️ ```+ source /Users/zen/.bashrc```➡️ ```++ alias 'p=python -m SimpleHTTPServer'```➡️ ```/usr/bin/alias: line 4: builtin: alias: not a shell builtin``` – Mars Robertson Feb 19 '17 at 10:34
  • @CharlesDuffy Attempt with the function - http://i.imgur.com/HTopxMr.png - command not fund. I didn't change anything in my ```.dotfiles```, I'm a web developer because I find visual work more aesthetically pleasing than bashing with command line. – Mars Robertson Feb 19 '17 at 10:39
  • @MichalStefanow, ...so, that tells us that `/usr/bin/alias` is being used in place of the builtin from *before* you source your dotfile, and rules out the hidden-characters theory. It'd be more useful to get a log from a completely new shell instance, so we can see what's actually turning off the builtin. `PS4=':$BASH_SOURCE:$LINENO+' bash -l -i -x` will collect that full initialization log. – Charles Duffy Feb 19 '17 at 17:37
  • @MichalStefanow, ...as for the function not working, I'd like to see the actual definition as you're using for it, *exactly* as entered. You can actually type that definition in at your terminal, btw, rather than putting it in your `.bashrc`. On a different note -- please use textual pastebins (https://gist.github.com/ and http://ix.io/ are both reputable ones that don't have ads) rather than screenshots -- the latter aren't amenable to copy/paste; aren't searchable; &c. – Charles Duffy Feb 19 '17 at 17:40
  • Hmm. `type alias` describing it as a builtin, but the external version being run are contradictory datapoints -- they can't both be true, which means that we've got two different contexts between where your various tests have been run. – Charles Duffy Feb 19 '17 at 17:42
  • @CharlesDuffy Dammit! Updated the question... Googling for ```/usr/bin/alias: line 4: builtin: alias: not a shell builtin``` leads to this very question. I'm using ```iTerm```, tried ```.profile``` as suggested here - http://superuser.com/questions/573633/bash-profile-not-sourced - but still struggling... – Mars Robertson Feb 19 '17 at 23:30
  • There are still several items suggested in this chat history that haven't been run down yet -- `enable -n` would be one of them. And I *would* like to see the logs from `bash -l -i -x` with the PS4 given above. – Charles Duffy Feb 20 '17 at 00:22
  • @CharlesDuffy Thank you for being so patient with me, here is the output of these commands: http://pastebin.com/xb406R0b – Mars Robertson Feb 21 '17 at 14:29
  • I know how to make an alias, this is probably the simplest way - https://coolestguidesontheplanet.com/make-an-alias-in-bash-shell-in-os-x-terminal/ - for some reason I cannot get it to work and because of `enable -n` and `bash -l -i -x` my terminal behaves differently... How do I restore defaults? – Mars Robertson Feb 21 '17 at 14:40
  • BTW, this is the part where I grumble about pastebin.com -- it's full of ads, so by using it you're pointing anyone without an adblocker towards a quite unpleasant (and potentially malware-laden, though I think they've switched to a more reputable ad vendor) experience. Please consider http://ix.io/ or https://gist.github.com/ in the future. – Charles Duffy Feb 21 '17 at 15:54
  • Anyhow, back towards topic -- frankly, `bash -l -i -x` makes it pretty clear that you don't have much going on configuration-wise, unless, say, it's environment variables *outside* of your bash installation impacting it. Could you capture the output from `env`? – Charles Duffy Feb 21 '17 at 15:59
  • (Also, just as a sanity check, what's your output from `echo "$BASH_VERSION"`?) – Charles Duffy Feb 21 '17 at 16:00
  • (and btw, `enable -n` having no output is entirely correct/desired behavior, so that's not getting us towards an explanation for the issue). – Charles Duffy Feb 21 '17 at 16:02
  • ...btw, you still haven't shown a log of the function being defined and not working, ideally with `set -x` active. I'd quite like to see that. – Charles Duffy Feb 21 '17 at 16:02
  • @CharlesDuffy - didn't realise Pastebin is like W3schools - here is the output of all the commands - https://gist.github.com/stefek99/cb656915806a800646ade8ce87b0ccc9 - including the proof that I didn't make the typo in `alias p='python -m SimpleHTTPServer'` - able to execute it, too bad `.profile` and .bash_profile` do not behave right :( – Mars Robertson Feb 22 '17 at 07:32
  • Okay, nothing going on in the environment; we can check shell variables and state, but any changes to those *should* have shown up in the `bash -x -l -i` log. Huh. I'm actually a bit stumped here -- making bash behave differently when sourcing something is *work*, and it's work that should have left a trace in the logs. Frankly, I'm curious enough to be willing to inspect the system myself, if you'd be up for a remote desktop session (or are liable to be passing through downtown Chicago); if you want to get in touch out-of-band, I'm charles@dyfis.net. – Charles Duffy Feb 22 '17 at 13:23
  • Magic. Email sent. I'm in the London timezone. Travelling soon... (so may not have a time right now but will figure it out) – Mars Robertson Feb 23 '17 at 01:36
  • BTW -- see http://superuser.com/a/244990/31769 re: differences between `~/.bashrc` and `~/.bash_profile`. – Charles Duffy Mar 06 '17 at 15:38

2 Answers2

1

Given the set of possibilities we've eliminated --

Since you're using bash 3.2, set -x may not be visibly rendering all hidden characters, such as a byte order marker at the beginning of your file.

If the BOM is in fact the problem, then the first line of the file will always cause an error regardless of its contents, and if you move the alias command to the second line, it will then function. Similarly, if you install a more recent version of bash from MacPorts or Homebrew, then running bash -x -l -i will show the hidden characters at the beginning of the command it's trying to run in the generated log.

To solve this, recreate the file in a text editor that doesn't save a BOM, or use "Save As..." and choose a format with no BOM in an editor that gives you the option.

Charles Duffy
  • 280,126
  • 43
  • 390
  • 441
  • Once again thank you for the most **EPIC** experience in the history of SO... You've spent so much time, including `chrome remote desktop` session... Simply **WOW** – Mars Robertson Apr 08 '17 at 06:08
-1

Run the alias command to display all created aliases. Also, you should use ~/.bashrc for aliases, not .bash_profile.

echo "alias p='python -m SimpleHTTPServer'" >> ~/.bashrc
source ~/.bashrc
miken32
  • 42,008
  • 16
  • 111
  • 154
Panta
  • 199
  • 3