bashrc alias nem fut le beírás után

SunFighter képe

Fórum: 

Sziasztok!

Az alábbi probléma merült fel nálam. Létrehoztam pár egyszerübb alias bejegyzést, hogy megkönnyítsem a terminálos beírásokat, de valamiér nem találja meg a rendszer az összes alias-t. Mi lehet a hiba?

# Saját parancsok listája
alias fel='apt-get install -y -f'
alias teszt='apt-get install -s'
alias le='apt-get purge --autoremove'
alias frissit='apt-get update && apt-get dist-upgrade && apt-get autoclean'
alias keres='apt-cache search'
alias ir='xed'
alias win='wine'
alias re_php='systemctl restart apache2'

 

Lefut a keres.

apa@apa-System:~$ keres firefox
firefox - Safe and easy web browser from Mozilla
firefox-dbg - Safe and easy web browser from Mozilla - debug symbols
firefox-dev - Safe and easy web browser from Mozilla - development files
firefox-locale-af - Afrikaans language pack for Firefox
firefox-locale-an - Aragonese language pack for Firefox
firefox-locale-ar - Arabic language pack for Firefox
firefox-locale-ast - Asturian language pack for Firefox
firefox-locale-az - Azerbaijani language pack for Firefox

lefut: az ir

apa@apa-System:~/Asztal$ ir Linux_parancsok.txt

megnyitja xed-del az asztalon lévő file-t

Nincs parancs:

le, fel, frissit, teszt

________________________________________

Válaszokat előre is köszönöm.

alias

A frissit használatánál ha nincs frissitendő, a promptot adja vissza. A többinél hogy adod ki a parancsot, pl. fel firefox?

Értékelés: 

0
Még nincs értékelve
SunFighter képe

alias

#1 igen. pl:

apa@apa-System:~/Asztal$ sudo fel firefox
[sudo] apa jelszava:        
sudo: fel: parancs nem található

sudo nélkül természetesen  kiírja, hogy nem vagyok root joggal.

a re_php is gyönyörüen lefut, az apache2 -re  bekéri ablakban a jogosultságom, utána újra indítja, ezért nem értem, hogy az egyik lefut, akkor a másik miért nem :)

 

Értékelés: 

0
Még nincs értékelve
kimarite képe

.baschrc

A .baschrc fájlban egy lehetséges megoldás:

# Alias definitions.
# You may want to put all your additions into a separate file like
# ~/.bash_aliases, instead of adding them here directly.
# See /usr/share/doc/bash-doc/examples in the bash-doc package.

if [ -f ~/.bash_aliases ]; then
    . ~/.bash_aliases
fi

Ha az aliasok a .bash_aliases fájlban vannak elmentve.

-----

A .profile fájl tartalma:

# ~/.profile: executed by the command interpreter for login shells.
# This file is not read by bash(1), if ~/.bash_profile or ~/.bash_login
# exists.
# see /usr/share/doc/bash/examples/startup-files for examples.
# the files are located in the bash-doc package.

# the default umask is set in /etc/profile; for setting the umask
# for ssh logins, install and configure the libpam-umask package.
#umask 022

# if running bash
if [ -n "$BASH_VERSION" ]; then
    # include .bashrc if it exists
    if [ -f "$HOME/.bashrc" ]; then
    . "$HOME/.bashrc"
    fi
fi

# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/bin" ] ; then
    PATH="$HOME/bin:$PATH"
fi

# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/.local/bin" ] ; then
    PATH="$HOME/.local/bin:$PATH"
fi

Értékelés: 

5
Átlag: 5 (1 szavazat)
kimarite képe

alias

#2 A „fel” alias a telepítés. Nincs telepítve a Firefox már?

apt-get install -y -f firefox-esr -s
NE FELEDJE: Ez csak szimuláció!
      Az apt-get rendszergazdai jogokat igényel a tényleges végrehajtáshoz.
      Ne feledje, hogy a zárolás is ki van kapcsolva,
      így ne számítson a jelenlegi helyzet valósságára!
Csomaglisták olvasása... Kész
Függőségi fa építése       
Állapotinformációk olvasása... Kész
firefox-esr már a legújabb verzió (60.8.0esr-1~deb10u1).
firefox-esr kézi telepítésűre állítva.
0 frissített, 0 újonnan telepített, 0 eltávolítandó és 0 nem frissített.

Csinálhatnád így:

alias fel='sudo apt-get install'
alias teszt='sudo apt-get install -s'
alias le='sudo apt-get purge'
alias frissit='sudo apt-get update && sudo apt-get dist-upgrade && sudo apt-get clean'

De ez a megoldás:

Add the following line to your ~/.bashrc:

alias sudo='sudo '

From the bash manual:

Aliases allow a string to be substituted for a word when it is used as the first word of a simple command. The shell maintains a list of aliases that may be set and unset with the alias and unalias builtin commands.

The first word of each simple command, if unquoted, is checked to see if it has an alias. If so, that word is replaced by the text of the alias. The characters ‘/’, ‘$’, ‘`’, ‘=’ and any of the shell metacharacters or quoting characters listed above may not appear in an alias name. The replacement text may contain any valid shell input, including shell metacharacters. The first word of the replacement text is tested for aliases, but a word that is identical to an alias being expanded is not expanded a second time. This means that one may alias ls to "ls -F", for instance, and Bash does not try to recursively expand the replacement text. If the last character of the alias value is a space or tab character, then the next command word following the alias is also checked for alias expansion.

(Emphasis mine).
Bash only checks the first word of a command for an alias, any words after that are not checked. That means in a command like sudo ll, only the first word (sudo) is checked by bash for an alias, ll is ignored. We can tell bash to check the next word after the alias (i.e sudo) by adding a space to the end of the alias value.

Forrás: https://askubuntu.com/questions/22037/aliases-not-available-when-using-sudo

Értékelés: 

5
Átlag: 5 (1 szavazat)
SunFighter képe

alias

#4 Végül is, alap hiba :) Talán a home könyvtáramba kellett volna  megirnom :)

Köszönöm a segítséget ;)

Értékelés: 

0
Még nincs értékelve
kimarite képe

alias

#5 Az eredmény a lényeg, hogy sikerült. :-)

Értékelés: 

0
Még nincs értékelve