You are not logged in.

#1 2023-02-04 10:14:41

Archibard
Member
Registered: 2023-02-04
Posts: 8

[SOLVED] Alias not working from .bashrc

Hi Archers!
I'm new here but I've been using Arch for some time, although I'm far from being a seasoned veteran. I tried to define a new alias in ~/.bashrc but it doesn't work. I tried restarting the terminal, then the whole computer and also tried issuing ". ~/.bashrc ", nothing works. By issueing alias, I get the default aliases but not my own. What am I doing wrong? I don't get it. I'm sitting here in my Arch T-shirt and Arch sweater and I'm starting to feel unworthy of them. sad big_smile

Btw, the alias I'm trying to create is the below one for playing a video file with Dolby Atmos passthrough:
alias atmos='mpv --audio-device='alsa/hdmi:CARD=NVidia,DEV=2' --audio-spdif=ac3,dts,dts-hd,eac3,truehd'

Thanks in advance for any help!

SOLUTION TLDR: Turns out, I was using zsh, not bash and had to add the alias in the .zshrc file.

Last edited by Archibard (2023-02-04 19:17:43)

Offline

#2 2023-02-04 10:28:02

seth
Member
From: Don't DM me only for attention
Registered: 2012-09-03
Posts: 68,329

Re: [SOLVED] Alias not working from .bashrc

I'd have a look at the quotation marks and maybe see whether nesting actually works if you also use the other type of quotes supported by bash.

Offline

#3 2023-02-04 10:32:01

mpan
Member
Registered: 2012-08-01
Posts: 1,491
Website

Re: [SOLVED] Alias not working from .bashrc

See bash: invocation for the description of a quite convoluted way bash executes various files at startup. Verify, if “~/.bashrc” is executed at all.

I also look suspiciously at those quotation marks, but executing this on my machine worked.

Last edited by mpan (2023-02-04 10:32:40)


Paperclips in avatars?
NIST on password policies (PDF) — see §3.1.1.2
Sometimes I seem a bit harsh — don’t get offended too easily!

Offline

#4 2023-02-04 10:41:12

seth
Member
From: Don't DM me only for attention
Registered: 2012-09-03
Posts: 68,329

Re: [SOLVED] Alias not working from .bashrc

but executing this on my machine worked.

Indeed, bash's smart enough.

tried issuing ". ~/.bashrc "

I tried to define a new alias in ~/.bashrc

Please don't paraphrase, https://bbs.archlinux.org/viewtopic.php?id=57855
In this case: especially post your .bashrc

Offline

#5 2023-02-04 12:20:55

Archibard
Member
Registered: 2023-02-04
Posts: 8

Re: [SOLVED] Alias not working from .bashrc

Thank you for the quick responses. Yes, single quotes are working but I tried double quotes, too.

See bash: invocation for the description of a quite convoluted way bash executes various files at startup. Verify, if “~/.bashrc” is executed at all.

I read that but I don't see any problem. It says that .bash_profile is executed first and that contains:

#
# ~/.bash_profile
#

[[ -f ~/.bashrc ]] && . ~/.bashrc

If I'm not mistaken, this checks the availability of the .bashrc file and loads it.

My .bashrc:

# colors
darkgrey="$(tput bold ; tput setaf 0)"
white="$(tput bold ; tput setaf 7)"
blue="$(tput bold; tput setaf 4)"
cyan="$(tput bold; tput setaf 6)"
nc="$(tput sgr0)"

# exports
export PATH="${HOME}/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:"
export PATH="${PATH}/usr/local/sbin:/opt/bin:/usr/bin/core_perl:/usr/games/bin:"

if [[ $EUID -eq 0 ]]; then
  export PS1="\[$blue\][ \[$cyan\]\H \[$darkgrey\]\w\[$darkgrey\] \[$blue\]]\\[$darkgrey\]# \[$nc\]"
else
  export PS1="\[$blue\][ \[$cyan\]\H \[$darkgrey\]\w\[$darkgrey\] \[$blue\]]\\[$cyan\]\$ \[$nc\]"
fi

export LD_PRELOAD=""
export EDITOR="vim"

# alias
alias ls="ls --color"
alias vi="vim"
alias shred="shred -zf"
alias wget="wget -U 'noleak'"
alias curl="curl --user-agent 'noleak'"
alias atmos='mpv --audio-device='alsa/hdmi:CARD=NVidia,DEV=2' --audio-spdif=ac3,dts,dts-hd,eac3,truehd'
alias sudo='sudo -v; sudo '

# source files
[ -r /usr/share/bash-completion/completions ] &&
  . /usr/share/bash-completion/completions/*

Offline

#6 2023-02-04 15:26:35

adventurer
Member
Registered: 2014-05-04
Posts: 127

Re: [SOLVED] Alias not working from .bashrc

Did you execute

source .bashrc 

after adding your alias?

Offline

#7 2023-02-04 15:42:00

seth
Member
From: Don't DM me only for attention
Registered: 2012-09-03
Posts: 68,329

Re: [SOLVED] Alias not working from .bashrc

the OP wrote:

also tried issuing ". ~/.bashrc ", nothing works.


Sanity check:

echo $SHELL
alias atmos='mpv --audio-device='alsa/hdmi:CARD=NVidia,DEV=2' --audio-spdif=ac3,dts,dts-hd,eac3,truehd'
type atmos
atmos /path/to/some/file.mp3

Can you add other aliases to your bashrc

alias foo=bar

Offline

#8 2023-02-04 16:32:14

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,402
Website

Re: [SOLVED] Alias not working from .bashrc

FWIW, the quotes "work" because they are irrelevant.  The internal quotes are not needed at all as there are no spaces or other special characters in the inner-most quote.  And bash is not smart enough to interpret these as nested quotes: there are four of them, so bash reads it as a one quoted string between the first two, one unqoted string before the next, and another quoted string until the last one, e.g., quoted in red:

alias atmos='mpv --audio-device='alsa/hdmi:CARD=NVidia,DEV=2' --audio-spdif=ac3,dts,dts-hd,eac3,truehd'

This *only* works because there are no spaces in the non-red non-quoted portion (which coincidentally is also why those are irrelevant in the first place).  So while it's fine the way it is, it's fine due to some very unusual coincidences and could quite easily give a false sense of security leading to very likely breakage when the command is later modified (e.g., to add a space inside the "internal" quotes).  So it'd be better to just remove the inner quotes entirely.

But this is tangential to the current issue of the alias not being available.

Last edited by Trilby (2023-02-04 16:33:11)


"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Offline

#9 2023-02-04 18:16:03

Archibard
Member
Registered: 2023-02-04
Posts: 8

Re: [SOLVED] Alias not working from .bashrc

Thanks Trilby, for the clarification.

seth wrote:

Can you add other aliases to your bashrc

No, I can't, none of the aliases work in .bashrc.

adventurer wrote:

Did you execute

source .bashrc

I did, but I forgot to mention what happened. When I execute it, I get this error and a crazy prompt:

>>> source .bashrc 
/usr/share/bash-completion/completions/2to3:37: command not found: complete
\[\][ \[\]\H \[\]\w\[\] \[\]]\[\]$ \[\]

The last line is the actual prompt. If I restart Konsole, it goes back to normal.

Last edited by Archibard (2023-02-04 18:17:11)

Offline

#10 2023-02-04 18:21:38

Scimmia
Fellow
Registered: 2012-09-01
Posts: 13,030

Re: [SOLVED] Alias not working from .bashrc

Archibard wrote:
seth wrote:

Can you add other aliases to your bashrc

No, I can't, none of the aliases work in .bashrc.

Seriously? seth asked for a bunch of information, and you pick out probably the least important and ignore the rest?

Last edited by Scimmia (2023-02-04 18:21:55)

Offline

#11 2023-02-04 18:28:44

Head_on_a_Stick
Member
From: The Wirral
Registered: 2014-02-20
Posts: 8,999
Website

Re: [SOLVED] Alias not working from .bashrc

^ It's possible the OP didn't recognise that the statement "sanity check" was a request for the output of those commands.

I think we also need to see

type "$0"

Jin, Jîyan, Azadî

Offline

#12 2023-02-04 18:34:59

seth
Member
From: Don't DM me only for attention
Registered: 2012-09-03
Posts: 68,329

Re: [SOLVED] Alias not working from .bashrc

>>> source .bashrc

For the prompt I'm gonna bet everyones elses right arm this is fish.

Offline

#13 2023-02-04 19:04:35

Archibard
Member
Registered: 2023-02-04
Posts: 8

Re: [SOLVED] Alias not working from .bashrc

Head_on_a_Stick wrote:

^ It's possible the OP didn't recognise that the statement "sanity check" was a request for the output of those commands.

I think we also need to see

type "$0"

Exactly.

So the outputs:

>>> echo $SHELL
/bin/zsh

>>> alias atmos='mpv --audio-device='alsa/hdmi:CARD=NVidia,DEV=2' --audio-spdif=ac3,dts,dts-hd,eac3,truehd'

>>> type atmos
atmos is an alias for mpv --audio-device=alsa/hdmi:CARD=NVidia,DEV=2 --audio-spdif=ac3,dts,dts-hd,eac3,truehd

>>> atmos video.mp4 
 (+) Video --vid=1 (*) (av1 460x238 29.970fps)
 (+) Audio --aid=1 (*) (opus 2ch 48000Hz)
AO: [alsa] 48000Hz stereo 2ch s32
VO: [gpu] 460x238 yuv420p
AV: 00:00:08 / 00:01:35 (9%) A-V:  0.000
Track switched:
 (+) Video --vid=1 (*) (av1 460x238 29.970fps)
     Audio --aid=1 (*) (opus 2ch 48000Hz)
V: 00:00:11 / 00:01:35 (12%)
Track switched:
 (+) Video --vid=1 (*) (av1 460x238 29.970fps)
 (+) Audio --aid=1 (*) (opus 2ch 48000Hz)
AO: [alsa] 48000Hz stereo 2ch s32
AV: 00:00:24 / 00:01:35 (26%) A-V: -0.000

Exiting... (Quit)

>>> type "$0"
/bin/zsh is /bin/zsh

The video started, though there was no sound. But it's a different issue, there's no sound even if I start it from GUI.

Offline

#14 2023-02-04 19:05:42

Archibard
Member
Registered: 2023-02-04
Posts: 8

Re: [SOLVED] Alias not working from .bashrc

Wait, is this the problem? That it's zsh? Whaaat? big_smile

Offline

#15 2023-02-04 19:08:42

seth
Member
From: Don't DM me only for attention
Registered: 2012-09-03
Posts: 68,329

Re: [SOLVED] Alias not working from .bashrc

zsh will not load .bashrc for obvious reasons.
Try ~/.zshrc

And remove the ugly fish-promt.
It cost a lot of fine people their right arms tonight tongue

Offline

#16 2023-02-04 19:09:00

Archibard
Member
Registered: 2023-02-04
Posts: 8

Re: [SOLVED] Alias not working from .bashrc

OK, yes, of course this was it. Sorry for the lame problem and thank you very much for the help, everyone!

Offline

#17 2023-02-04 19:13:23

seth
Member
From: Don't DM me only for attention
Registered: 2012-09-03
Posts: 68,329

Re: [SOLVED] Alias not working from .bashrc

Please always remember to mark resolved threads by editing your initial posts subject - so others will know that there's no task left, but maybe a solution to find.
Thanks.

Offline

#18 2023-02-04 19:14:45

jasonwryan
Anarchist
From: .nz
Registered: 2009-05-09
Posts: 30,426
Website

Re: [SOLVED] Alias not working from .bashrc

Archibard wrote:

Wait, is this the problem? That it's zsh? Whaaat? big_smile

How did you install Arch?


Arch + dwm   •   Mercurial repos  •   Surfraw

Registered Linux User #482438

Offline

Board footer

Powered by FluxBB