Bash warning from created alias

Hello!

So I have created an alias in ~/.alias as such:
alias update="sudo zypper refresh && sudo zypper dup"

The alias itself works as intended, however whenever I open a new terminal I receive the following message in it:

bash: alias: zypper: not found
bash: alias: refresh: not found

Have I done something wrong?
Or does anyone have an idea if this can be turned off / muted somehow?

Thanks for the help!

@Winter Hi your repos should be set to auto refresh so just a zypper dup will suffice, also use full path to zypper which zypper.

zypper lr -E

Look at the 4th column should be set to Yes?

Not a sudo user here but apparently you need to define an

alias

with

alias sudo='sudo ’

According to this Wiki, good luck.

But most probably a function should do, without going to create an alias for sudo itself, something like:

update() { sudo zypper refresh && sudo zypper dup; }

Hi!

which zypper returns usr/bin/zypper so I tried to replace the zypper in my alias with that, as such:

alias update="sudo /usr/bin/zypper refresh && sudo /usr/bin/zypper dup"

The command itself still works however I still get the same “not found” errors when opening a terminal.
I restarted my pc to be sure.

zypper lr -E returned the following table, it seems auto-refresh is on.
The reason I have the zypper refresh command is because I had to run that once to update vs code, could be that the auto refresh is only executed occasionally?

#  | Alias                            | Name     | Enabled | GPG Check | Refresh
---+----------------------------------+----------+---------+-----------+--------
 1 | download.opensuse.org-non-oss    | Main R-> | Yes     | (r ) Yes  | Yes
 2 | download.opensuse.org-oss        | Main R-> | Yes     | (r ) Yes  | Yes
 3 | download.opensuse.org-tumbleweed | Main U-> | Yes     | (r ) Yes  | Yes
 4 | ftp.gwdg.de-openSUSE_Tumbleweed  | Packma-> | Yes     | (r ) Yes  | Yes
 5 | google-chrome                    | google-> | Yes     | (r ) Yes  | Yes
 6 | miktex-opensuse-15               | MiKTeX-> | Yes     | (r ) Yes  | No
 7 | openSUSE-20230301-0              | openSU-> | Yes     | (r ) Yes  | Yes
 9 | repo-openh264                    | Open H-> | Yes     | (r ) Yes  | Yes
10 | repo-source                      | openSU-> | Yes     | (r ) Yes  | Yes
11 | vscode                           | vscode   | Yes     | (r ) Yes  | Yes

Hi!

I’m not very good with bash scripting but I messed around a bit with your suggestions however I still cant get rid of the error messages…

I tried to create the sudo alias as you suggested but it didnt change anything.
I tried to create a local function in the .alias file that gets called by an alias aswell :

alias update='zypperUpdate'

zypperUpdate () { sudo zypper refresh && sudo zypper dup; }

I could still update my system with the update alias however the errors are still there when I open a terminal.

Finally i tried moving the update function to its own file, .updateWithZypper.sh and then I called that from the alias as such:

alias update='. ~/.updateWithZypper.sh'

Still works but with the same error messages…

EDIT:
I tried to remove my alias command and only have the bash script with the update function in my home folder but I still get the same errors, could it be something else that is causing these errors then?

You may open a root shell su -, which is the real thing compared to sudo ...

3400G:~ # cat .alias
alias repos='zypper repos --alias --uri --refresh --show-enabled-only --priority' 
alias dupd='zypper --non-interactive dist-upgrade --dry-run --download-only' 
alias dupi='zypper --non-interactive dist-upgrade' 
3400G:~ # 

The above aliases are straight forward and require not tinkering for most users.

3400G:~ # repos
#  | Alias                | Enabled | GPG Check | Refresh | Priority | URI
---+----------------------+---------+-----------+---------+----------+---------------------------------------------------------------------------------------
 5 | Packman              | Yes     | (r ) Yes  | Yes     |   90     | https://ftp.fau.de/packman/suse/openSUSE_Tumbleweed/
21 | repo-non-oss         | Yes     | (r ) Yes  | Yes     |   99     | https://download.opensuse.org/tumbleweed/repo/non-oss/
22 | repo-oss             | Yes     | (r ) Yes  | Yes     |   99     | https://download.opensuse.org/tumbleweed/repo/oss/
24 | repo-update          | Yes     | (r ) Yes  | Yes     |   99     | https://download.opensuse.org/update/tumbleweed/
13 | home_kukuk_qmapshack | Yes     | (r ) Yes  | Yes     |  100     | https://download.opensuse.org/repositories/home:/kukuk:/qmapshack/openSUSE_Tumbleweed/
15 | jalbum               | Yes     | (  ) No   | Yes     |  100     | https://jalbum.net/download/software/yumrepo/
3400G:~ # 

Hi!

I’m not entirely sure how this helps, but the su - command is nice to know however!
But I get the same error message when I run it, basically I just don’t need to use ‘sudo’ while I’m in the root shell right?
It seems more like I’ve created an alias that contain zypper somewhere that it doesn’t like…
I have tried to grep for it but no luck so far…

Bash alias command does pure textual substitution. It does not try to interpret the content of alias, nor is this content interpreted when alias is substituted.

Do you get the same errors when you simply invoke bash?

I tried,

~> bash
bash: alias: zypper: not found
bash: alias: refresh: not found

So yes just writing bash causes it to appear!
Any idea what can cause this?

Run

script
bash -x
exit
exit

and post file typescript in the current directory (better upload to https://susepaste.org).

1 Like

I found the issue thanks to that!
Turned out I had a file in etc/bash.bashrc.local that contained an alias with zypper refresh!

Thank you so much for the help! :slight_smile:

It would still be helpful to all others if you posted the exact alias definition.

1 Like

For what its worth, you should only have an alias or a function with the same name, you cant have both . Running

alias

should show you all the defined aliases on your system.

1 Like

sudo comes with configuration files. Settings are different for different distributions, which frequently starts effing discussions.

su - is easy. sudo ... comes with side effects, see above.

You may want to read the fine manual. From man alias:

   OPERANDS

   The following operands shall be supported:

   alias-name
             Write the alias definition to standard output.

   alias-name=string
             Assign the value of string to the alias alias-name.

   If no operands are given, all alias definitions shall be written to standard output.

Show your aliases as told by man alias.

1 Like

Ok so I did:

script
bash -x
exit
exit

In the file typescript that was created in the current directory I found the following lines:

...
+ test -s /etc/bash.bashrc.local
+ . /etc/bash.bashrc.local
++ alias dup=sudo zypper refresh
bash: alias: zypper: not found
bash: alias: refresh: not found
...

By removing this “alias” line from /etc/bash.bashrc.local the “not found” warnings stopped appearing every time I opened a terminal.

My alias is now only defined in ~/.alias as:

alias update="sudo zypper refresh && sudo zypper dup"

which works and there are no warnings.

As a side note; executing the “alias” command in the terminal did not display the “alias” that was “defined” in /etc/bash.bashrc.local

Thanks for the help everyone!

Thanks for the comprehensive feedback!

Shell programming can be fun. Some helpful reading:

Whenever feasible I avoid shell programming and use systemd services. They are running in the system slice and thus they are robust:

3400G:~ # systemctl status dup|cat
○ dup.service - Dist Upgrade
     Loaded: loaded (/etc/systemd/system/dup.service; static)
     Active: inactive (dead) since Sat 2023-04-08 05:44:03 CEST; 2h 25min ago
   Duration: 8min 37.436s
TriggeredBy: ● dup.timer
    Process: 30418 ExecStart=/usr/bin/zypper --non-interactive dist-upgrade (code=exited, status=0/SUCCESS)
   Main PID: 30418 (code=exited, status=0/SUCCESS)
        CPU: 58.639s

Apr 08 05:43:58 3400G [RPM][459]: install libreoffice-filters-optional-7.5.2.1-1.2.x86_64: success
Apr 08 05:43:58 3400G [RPM][459]: Transaction ID 6430e2fe finished: 0
Apr 08 05:43:58 3400G zypper[30418]: (58/58) Installing: libreoffice-filters-optional-7.5.2.1-1.2.x86_64 [...done]
Apr 08 05:43:58 3400G zypper[30418]: Executing %posttrans script 'adobe-sourcesans3-fonts-3.052-1.1.noarch.rpm' [..
Apr 08 05:43:58 3400G zypper[30418]: Use of uninitialized value $ENV{"HOME"} in concatenation (.) or string at /usr/sbin/fonts-config line 391.
Apr 08 05:44:01 3400G zypper[30418]: ......done]
Apr 08 05:44:03 3400G zypper[30418]: There are running programs which still use files and libraries deleted or updated by recent upgrades. They should be restarted to benefit from the latest updates. Run 'zypper ps -s' to list these programs.
Apr 08 05:44:03 3400G zypper[30418]:  
Apr 08 05:44:03 3400G systemd[1]: dup.service: Deactivated successfully.
Apr 08 05:44:03 3400G systemd[1]: dup.service: Consumed 58.639s CPU time.
3400G:~ # 

Maintenance and administration is made easy: Understanding Systemd Units and Unit Files | DigitalOcean

3400G:~ # systemctl cat dup
# /etc/systemd/system/dup.service
[Unit] 
Description=Dist Upgrade

[Service] 
ExecStartPre=/usr/bin/nm-online
ExecStart=/usr/bin/zypper --non-interactive dist-upgrade
3400G:~ # 
1 Like