How do you get terminal to explain a command? - terminal

For example, I want to know what -r does in terminal. I can't easily find any documentation but I assume in terminal there must be way to have a command explained. I tried info [-r] and help -r, but these combinations haven't worked. I'm sure it is very simple. Thanks.

Each command-line tool supports different options.
There is no standardization, even if a lot of commands implement the same arguments for the same actions (as -r).
So you need to get help on a specific command.
You can do it with the man command, to get the complete manual of the command:
man [COMMAND]
Like:
man ls
A lot of commands also implements the --help or -h arguments, for a shorter help dialog.

Related

Why does an error keep popping up when "ls -a " is used?

I'm creating a discord bot and also following a tutorial at the same time. I've managed to stumble upon an error cause by "ls -a"
I'm also new to this so it would mean a lot if anyone could explain this is simple words for me to understand!
Thank you
ls -a error screenshot
That tutorial is meant for POSIXy systems such as Linux, and you're using Windows.
Windows' PowerShell happens to have an alias ls for listing items in a directory, but it does not directly support -a (which the POSIX ls command does support).

Various flags in bash

I see many times flags such as if [-n ${Parameter}] or echo -n <string>. Sometimes, I have seen flags like -r and others used. However, I don't know how to search for the meaning of these flags on web. Could someone send me some link where I can understand as to what they mean or some general note as to how should I search for them on google? Thanks!
You can of course check the doc on internet https://ss64.com/bash/if.html
Or if you have access to a linux or mac machine, just check out the installed doc !
Try man if for example.
Also, man could have multiple pages for the same query, for example man open will show the manual of openvt on my machine and is a command line executable. But writting man 2 open gives you the manual of the C open function.
So by default man gives you manual of bash/command line and then C function.
So man open could be written man 1 open
This is really useful if you don't have an internet access or if the version of the tools that you want to use is different from the "normal" one. I think about sed for example, that is different from linux and mac. So they has different manual.
Of course there is a man of man ... :)
man man
I forgot to talk about help, most (and decent) program has the -h or/and --help. Most of the time the manual page shows much more information.

How to run history command in script

I have one script like
history
test.sh file in that I just put history
Now I run sh test.sh
Then it gives error like : history: command not found
Thanks In Advance
history is a command of the shell, so it should not look for it as if it were an external command (like ls)
I made a quick test and did not experience your problem, although I needed to use
set -o history
in order for history to display.
Can you provide further details?

What is wrong with this .command file?

This is my script to automate the git push of my static blog.
When I run each command one by one in the Terminal, it works. Do I need to add delays, maybe it's going too fast. The pelican command (static website generator) takes quite a lot of time (2 seconds). Is the rest of the script crashing during that?
#!/bin/sh
dropbox
cd blog
pelican . -s /Users/Paul-Arthur/Desktop/Desktop/Dropbox/blog/pelican.conf.py -t subtle
cd output
git add .
git commit -m 'commit'
git push
Updated: Sorry, yeah dropbox is a custom command in my bash_profile (this is not the problem, it works I know ;) ).
Sadly, when I click my script, it executes (but does not work) extremely quickly so I cannot see the errors.
Here is the output from the calepin command. The errors are normal and I expect it to run with that. Do you think that this is the problem? If so what can I do?
familys-imac:blog Paul-Arthur$ pelican . -s /Users/Paul-Arthur/Desktop/Desktop/Dropbox/blog/pelican.conf.py -t subtle
ERROR: Skipping ./articles/aboutme.md: impossible to find informations about 'title'
ERROR: Skipping ./articles/static_sites.md: impossible to find informations about 'title'
familys-imac:blog Paul
It might be due to the « cd » command, since it's not a command, it is a builtin from the shell, and doesn't act like a command.
To debug it, try adding «pwd» command inside your script before and after the «cd» line, to be sure the working directory has change.
It could also be due to the shell you are using, in the shebang (first line of your script), you are using the /bin/sh script. Is it the good one ? When you do it in your shell, you are maybe using another like bash, dash, zsh etc.
To determine that, type that in your current shell :
which `echo $0`
You will get an answer like :
/bin/bash
or something like this. Use this in your shell script :
#!/bin/bash
And try again your script.
Good luck with your project.

In bash, environmental variables not tab-expanding correctly

In bash, environmental variables will tab-expand correctly when placed after an echo command, for example:
echo $HOME
But after cd or cat, bash places a \ before the $ sign, like so:
cd \$HOME
If I use a variable as the second argument to a command, it won't expand at all:
cp somefile $HOM
What mysterious option do I have in my .bashrc or .inputrc file that is causing me such distress?
What you're describing is a "feature" introduced in bash 4.2. So you don't have any mysterious option causing you distress, but just "intended" behaviour.
I find this very annoying since I preferred it the way it used to be and haven't found any configuration options yet to get the earlier behaviour back. Playing with complete options as suggested by other answers didn't get me anywhere.
Try complete -r cd to remove the special programmatic completion function that many Linux distributions install for the cd command. The function adds searching a list of of directories specified in the CDPATH variable to tab completions for cd, but at the expense of breaking the default completion behavior.
See http://www.gnu.org/software/bash/manual/bashref.html#Programmable-Completion for more gory details.
For the second instance, you can press ESC before tab to solve it.
I don't know the solution to your problem, but you could look in /etc/bash_completion or the files under /etc/bash_completion.d to determine what commands use autocompletion and how.
help complete
Might also be helpful.
The Bash Reference Manual has more information than you might want on expansion errata.
Section 8.7 looks like it would be the place to start. It give information on the 'complete' function, among other things.
Check the answer for
https://superuser.com/questions/434139/urxvt-tab-expand-environment-variables by Dmitry Alexandrov:
This is about direxpand option. $ shopt -s direxpand and $FOO_PATH/ will be expanded by TAB.
I'm answering 4-year-old question! Fantastic!
This is a bash bug/feature which was unintentionally introduced in v4.2, and was unnoticed for a long period of time. This was pointed out by geirha in this tread. Confirmed as unintended feature here
I came across this problem when running Ubuntu at home. At work I have bash-3.00, so I've spent some time browsing around to see what's going on. I wonder if I can 'downgrade'....

Resources