bash - make command shorter

https://forums.opensuse.org/showthread.php/528761-Scanvirus-beta5-offical-release

I’v found ‘scanvirus’ on the command line no longer works in 'home/bin/. Displays ‘command-not-found’.

How do I change the code to use ‘scanvirus’ without the user entering new commands?

/home/bin #

‘./scanvirus’ → ‘scanvirus’

Hi,

Is

$HOME/bin

still in your PATH?

What is the output of

echo "$PATH"

What is the output of

type -a scanvirus

Please, also describe what the output of “which -a scanvirus” is.

Please also make clear that this is not about /home/bin ( shouldn’t exist ) but /home/YOURUSER/bin

I launch a terminal window from where it’s located. (and enter superuser mode)
/home/username/bin/

#echo $path
(blank line)

#type -a scanvirus
bash: type: scanvirus: not found

I took a shortcut that made it unclear. :\

/home/username/bin/

Correction:

echo $PATH

/sbin:/bin:/usr/sbin:/usr/bin

So,
I guess it should be clear that your app isn’t in your $PATH?
Either add the location of your app or if you intend to make your app accessible by all including the system, you should install into one of the root directories and not a User directory.

TSU

Hi,

You said that it was working before and it was in

/home/user/bin

So what did you change? did you change the location of the script?

Any how

/home/user/bin

is only available to the certain user and it will not be in the PATH of the other users in the system (root user included).

If you want the script to be available to everybody in the system you can put it in

/usr/local/bin

If you want it only to be accessible to the root user

/usr/local/sbin

The key word here is local since that script is made/created by the local administrator which happens to be you. Of course everyone can access the /usr/local/sbin if they use the absolute path, it is just not the default for everyone, at least not in openSUSE. Also you can put it anywhere else if you like say like in /bin and /usr/bin. So where will you put your script will depend on what your goal is.

Hi
I would surmise that you may have changed something in your ~/.profile to add a path? If not then in /etc/profile or /etc/profile.d/ directory

The default PATH I see is;


env |grep "PATH"
...
(TW)
PATH=/home/<username>/bin:/usr/local/bin:/usr/bin:/bin:/usr/lib/mit/sbin
(LEAP 15)
PATH=/home/<username>/bin:/usr/local/bin:/usr/bin:/bin

If scanvirus is in /home/user/bin, and you run it as the root user, it indeed won’t start. You should then cd /home/usr/bin, and then invoke ./scanvirus

In the previous version of opensuse, I did this.

desktop->click on “home”->click “bin” folder->bin folder: click open terminal.
su ->enter password
scanvirus

Opensuse leap 42.3 -->opensuse leap 15, full install, erasing all previous partitions. However, did that with the opensuse before ‘42.3’. 42.2 -->42.3 scanvirus worked.

Then → copy the script from backup → /home/user/bin/

(see previous message).

Anyhow

/home/user/bin

is only available to the certain user and it will not be in the PATH of the other users in the system (root user included)

If you want the script to be available to everybody in the system you can put it in

/usr/local/bin

If you want it only to be accessible to the root user

/usr/local/sbin

The key word here is local since that script is made/created by the local administrator which happens to be you. Of course everyone can access the /usr/local/sbin if they use the absolute path, it is just not the default for everyone, at least not in openSUSE. Also you can put it anywhere else if you like say like in /bin and /usr/bin. So where will you put your script will depend on what your goal is.

The goal was to create a fully functional command line virus scanner with all the features of GFX anti-virus scanner. With each version, it’s closer to that goal.

It can only be run in superuser mode. In my case, only one admin. However, more than one admin could run it. Both might try to run it at the same time. Another future to bug to fix.

So, this is the folder it should be placed in?

/usr/local/sbin

Yes, the $PATH was changed. I searched the internet and figured out this line as a solution.

PATH="$PATH:/home/$USER/bin"

This only works once per terminal session

                                   "You need to add it to your ~/.profile or ~/.bashrc file."

So, which file to I append this to?

At login, a user’s PATH variable is initially setup by the system file ‘/etc/profile’ – if this file is modified, then ** ALL ** users (including the ** SYSTEM ** users) on the system will be affected by the change …

After the login process has read the system-wide ‘/etc/profile’ file, if the Bash shell is involved, it then looks for a couple of user Bash files and then ‘~/.profile’ – even if Bash isn’t involved – the case for some GUI Desktop environments – IOW ‘~/.profile’ is always read …

Therefore, add the following lines to the user’s ‘~/.profile’ file:


PATH=${PATH}:"«The complete path to the user's specific directory to be included in the $PATH environment variable.»"
export PATH

  • Please note the :" … "
    syntax in the ‘PATH=’ statement …

Hi,

~/.profile 

is the correct place to put an additional PATH value and you need to export that PATH, you will see a commented example in that file.
The only thing to note is the order of COMMAND EXECUTION from bash see.

PAGER='less +/^COMMAND\ EXECUTION' man bash

To make it short bash search for the exectuable in the PATH from left to right. Just in case you have two executable that has the same name. so instead of

export PATH="$PATH:/home/$USER/bin"

I suggest to do

export PATH="/home/$USER/bin:$PATH

In your ~/.profile, Im not sure if the root user has a ~/.profile by default though, just create one if needed.

Hi,

Sorry, the last post had a typo. Either remove the quote or add a trailing quote on the PATH assignment.

Hi,

One more thing to add, avoid using the hard coded path such as /home/bin when adding a path value, instead use

"$HOME/bin"

just to be safe since the root user home bin is

/root/bin

as root and a normal user you can check that out.

echo "$HOME/bin"

Some things to clear up… /home/username/bin/scanvirus
Before latest update to opensuse leap.

normal:
>scanvirus
command not found
superuser
#scanvirus
command not found

After update

normal:
>scanvirus
==== superuser only ==== (scanvirus message)
superuser
#scanvirus
command not found

Any user with the admin should be able to run it. I’v never run it as ‘root’ user. I think I understand now. I tried putting into the ‘usr/local/bin and usr/local/bin’. Those aren’t listed in the path below. So, I get ‘command not found’.

The default $PATH in opensuse leap 15

 # echo $PATH
/sbin:/bin:/usr/sbin:/usr/bin

‘usr/sbin’ linux default commands. usr/bin are the installed app commands. Right?

sbin= SystemBINarys
bin= installed BINArys

As an installed app, it should go into usr/bin

If I use the /local/ folders, I will need to add a permanent $PATH change. I need to keep the install simple.

/home/username/bin/scanvirus → usr/bin/scanvirus

That should be the correct folder placement ‘scanvirus’…

scanvirus now will run in any folder. :slight_smile: