How to get all possible value of a certain linux command? - linux

For example, now I want to write a bash script in which I check the name of the running hosting system. The first command I would think of is uname -s. But I want to target some platform that is not available on my machine right now (like Cygwin, MinGW,...) and I want to make sure that I wrote the right name in the if condition. So the question is that how I can list all possible values of uname -s command (to avoid the headache for the wrong condition and who knows what's next...), and even for some commands which have the same characteristics?

Actually, after posting the question, I found out that there is a wiki page about the command uname which gives pretty much the information I need :D Never know that Wiki can be useful like that in this case

Related

Bash script to switch to root user with password (no additional libraries like expect can be used)

su
Enter Password: abcd
I need to be able to do the above process through a shell script. The issue is that it needs to be done with only the basic set of libraries that are available. No additional libraries can be used (eg except). Kindly do not suggest the usage of "sudo" or other things, this is the exact thing I need to do.
I have tried the following:
echo "abcd" | su
But it still ends up asking for the password again.
You should try NOPASSWD option. Use it for the particular command which you are going to execute for security reasons. Here are two methods explained but i think second one is what exactly you need.

Is there a way to retrieve the script path called by a user-defined command?

I'm a newbie in GNU/Linux and, for a project, I need to do some reverse engineering. At a given line in a script, there is a command:
dc 27 /A_PATH/ 32
I'm almost sure the "dc" command was previously added to the path/simlink/(?) by a previous developper. When executed, the command allows to run a simulation over the case indicated by the PATH. Yet, I don't know the meaning of the two other parameters (27 and 32) and I would need to bring some change in the way the simulation is executed.
Therefore, I would like to know how to obtain the address of the executable called when a user-defined bash command is runned.
I hope the vocabulary is correct, and, thank you already for the help.
As stated in comments :
which <command>
or with shell built-in :
type -p <command>

Easier navigation through filesystem in linux shell (cli)

I often find myself taking a lot of time to navigate through my filesystem when using the linux shell. This generally occurs because the autocompletion of bash only works if you provide the start of the file/dirname. What I often end up in is a lot of 'ls' with 'grep' commands, finally doing a 'cd'.
When you use a GUI based filebrowser (like Nautilus) you can type any part of a file/dirname and it will have matches that it jumps to directly. This makes it a lot easier and faster to navigate.
I wonder if anybody knows any great tools that helps with this problem. I know of the existence of Midnight Commander, though I never really used it for real and I couldn't figure out a direct solution for my problem the first couple of times I tried it. Also it seems not suitable because I want to have my shell's current working directory to be changed so I can do stuff there, instead of being stuck in an external program like Midnight Commander.
Try autojmp
https://github.com/joelthelion/autojump
And following article provides another solution
http://jeroenjanssens.com/2013/08/16/quickly-navigate-your-filesystem-from-the-command-line.html
You can first use the autocd or autopushd in zsh. You would just have to type the directory you want to go to, without the hassle of typing cd or pushd everytime.
You also have the globing possibility. For example, if I got those file in a directory:
1-a.tar
1-b.tar
c.tar
I can just type
*a.tar
without caring about the beginning of the file.
As a last solution you can always use an alias to the find command with a personalized option.

Is there a Linux command to replicate/replace the "banner" command?

I am writing a script on Red Hat Linux (I forget the version) that needs a header, but the banner command is not there for me to use and I won't be able to get it installed. I read via Google that it may well have been deprecated.
So is there a new version of the command that produces similar results, or a way I can replicate the command, or even just temporarily change the script output so that characters are a different size?
I've tried looking at stty but we don't access via xterm, we log in directly via putty.
In its simplest form, 'banner' is less than a few pages of code (e.g. this one). Perhaps you could just compile and run it from your home directory?
Use some web site, for example http://patorjk.com/software/taag/.
If you need it frequently you can create a script to scrap the result.
BTW, stty has nothing to do with your problem, I don't know why you mentioned it.

Show last command with up arrow on a linux c shell

I have implemented a simple linux shell in c. Now, I am adding some features and one I immediately thought about was to be able to show the last commands with the up arrow.
Question 1:
However, I have no idea how to accomplish this. Do you?
Question 2:
Any comment on how to store the "history" commands are also appreciated. I suppose something like a queue which allows access to all elements would be a good idea. Am I wrong? Do I have to implement it or is there already some good implementation out there I should know about?
Thanks.
Build libedit or readline support into your shell.
If you want to be lazy, you can use rlwrap:
rlwrap prog
I wrote the shell for HelenOS. Grab the bzr repo and navigate to uspace/app/bdsh (bdsh stands for the (b)rain (d)ead (sh)ell).
Other contributors have since added line editing / history / tab completion to the functions that handle input. Its written purely in ANSI C, does not link against glibc and implements its own functions. The code (both in the shell and underlying HelenOS libc) is 3 clause BSD, you can use it in anything.
If nothing else, it might help to just examine the implementation to get started.

Resources