recentpopularlog in

kme : shell   246

« earlier  
Linux command line character limit - Server Fault
The shell/OS imposed limit is generally very long - usually one or two hundred thousand characters.
<code class="language-bash">getconf ARG_MAX</code>

will give you the maximum input limit for a command. On the Debian system I currently have a terminal open on this returns 131072 which is 128*1024. The limit is reduced by your environment variables as if my memory serves me correctly these are passed in the same structure by the shell, though that will only take off a few hundred characters in most cases. To find an approximation of this value run env | wc -c - this suggests 325 characters at the current time on this login on this machine.

Scripts are likely to permit this full length, but it is not unlikely that other utilities will impose their own limits either intentionally or through design issues. There may also be artificial limits to how long an individual argument on a long command line can be, and/or how long a path to a file can be.
linux  shell  environmentsize  commandline  solution 
july 2019 by kme
windows - How to fix PuTTY showing garbled characters? - Server Fault
The analogous fix on CentOS (7) is to use 'localectl', maybe, except that requires DBus to be running, which it isn't for a fresh-out-of-the-box Docker container. ¯\_(ツ)_/¯
If the locale returns something like POSIX, issue
<code class="language-bash">update-locale LANG=en_US.utf8</code>
at the command line - see thomas-krenn.com/de/wiki/Locales_unter_Ubuntu_konfigurieren – koppor Dec 19 '15 at 11:05
docker  utf8  characterencoding  locale  mojibake  terminal  unix  shell  ubuntu  solution  centos  sortof 
june 2019 by kme
GitHub - skywind3000/z.lua: A new cd command that helps you navigate faster by learning your habits
Via: https://www.linuxuprising.com/2019/02/zlua-faster-way-of-changing-directories.html
A new cd command that helps you navigate faster by learning your habits :zap: - skywind3000/z.lua
Paste this script in your .bashrc / .zshrc:
<code class="language-bash">function j() {
if [[ "$argv[1]" == "-"* ]]; then
z "$@"
else
cd "$@" 2> /dev/null || z "$@"
fi
}</code>

When you are using j xxx it will first try cd xxx and then z xxx if cd failed.
bash  shell  cli  lua  producitivity  terminal  frecency  alternativeto  fasd  autojump 
june 2019 by kme
Bash Reference Manual | https://www.gnu.org/
Words of the form $'string' are treated specially. The word expands to string, with backslash-escaped characters replaced as specified by the ANSI C standard.
bash  shell  shellscripting  ansicquoting  quoting  dammitbrain  reference 
may 2019 by kme
Intrepid command line directory traversal - BrettTerpstra.com | https://brettterpstra.com/
I use Terminal (well, iTerm 2) for file management on my Mac more often than I use Finder. Typing out long path names is often more tedious than drilling through Finder folders, though. I have enough
unix  shell  bash  commandline  filesystemnavigation  tipsandtricks 
april 2019 by kme
The #! magic, details about the shebang/hash-bang mechanism | https://www.in-ulm.de/
what's special about #!

#! was a great hack to make scripts look and feel like real executable binaries.

But, as a little summary, what's special about #!? (list mostly courtesy of David Korn)

- the interpretername must not contain blanks
- the length of the #! is much smaller than the maximum path length
- $PATH is not searched for the interpreter
- (apart from an absolute path, the #! line also accepts a relative path,
- and #!interpreter is equivalent to #!./interpreter,
- however, it's not of any practical use)
- the interpreter usually must no be a #! script again
- the handling of arguments in the #! line itself is varying
- the setuid mechanism may or may not be available for the script
- there's no way to express #!$SHELL

And why shebang? In music, '#' means sharp. So just shorten #! to sharp-bang. Or it might be derived from "shell bang". All this probably under the influence of the american slang idiom "the whole shebang" (everything, the works, everything involved in what is under consideration). See also the wiktionary, jargon dictionary or Merriam-Websters. Sometimes it's also called hash-bang, pound-bang, sha-bang/shabang, hash-exclam, or hash-pling (british, isn't it?).

According to Dennis M. Ritchie (email answer to Alex North-Keys) it seems it had no name originally.
And Doug McIllroy mentioned (TUHS mailing list), that the slang for # at Bell Labs most probably was "sharp" at the time.
bourne  bash  posix  shell  shebang  unix  linux  shellscripting  history  butwhy  explained 
february 2019 by kme
Man pages for Git Bash on Windows 7 - Super User | https://superuser.com/
Yeah, if you want man pages by default, it's actually more prudent to do a default install of Cygwin.

You /could/ install Python, then 'pip install tldr', but that's not a good solution for a workshop.
windows  bash  git  shell  unix  workshop  howto 
february 2019 by kme
The Unix Shell: Instructor Notes | https://swcarpentry.github.io/
Many people have questioned whether we should still teach the shell. After all, anyone who wants to rename several thousand data files can easily do so interactively in the Python interpreter, and anyone who’s doing serious data analysis is probably going to do most of their work inside the IPython Notebook or R Studio. So why teach the shell?

The first answer is, “Because so much else depends on it.” Installing software, configuring your default editor, and controlling remote machines frequently assume a basic familiarity with the shell, and with related ideas like standard input and output. Many tools also use its terminology (for example, the %ls and %cd magic commands in IPython).

The second answer is, “Because it’s an easy way to introduce some fundamental ideas about how to use computers.” As we teach people how to use the Unix shell, we teach them that they should get the computer to repeat things (via tab completion, ! followed by a command number, and for loops) rather than repeating things themselves. We also teach them to take things they’ve discovered they do frequently and save them for later re-use (via shell scripts), to give things sensible names, and to write a little bit of documentation (like comment at the top of shell scripts) to make their future selves’ lives better.

The third answer is, “Because it enables use of many domain-specific tools and compute resources researchers cannot access otherwise.” Familiarity with the shell is very useful for remote accessing machines, using high-performance computing infrastructure, and running new specialist tools in many disciplines. We do not teach HPC or domain-specific skills here but lay the groundwork for further development of these skills. In particular, understanding the syntax of commands, flags, and help systems is useful for domain specific tools and understanding the file system (and how to navigate it) is useful for remote access.

Finally, and perhaps most importantly, teaching people the shell lets us teach them to think about programming in terms of function composition. In the case of the shell, this takes the form of pipelines rather than nested function calls, but the core idea of “small pieces, loosely joined” is the same.

Installing Bash and a reasonable set of Unix commands on Windows always involves some fiddling and frustration. Please see the latest set of installation guidelines for advice, and try it out yourself before teaching a class.

Tab completion sounds like a small thing: it isn’t. Re-running old commands using !123 or !wc isn’t a small thing either, and neither are wildcard expansion and for loops. Each one is an opportunity to repeat one of the big ideas of Software Carpentry: if the computer can repeat it, some programmer somewhere will almost certainly have built some way for the computer to repeat it.

Building up a pipeline with four or five stages, then putting it in a shell script for re-use and calling that script inside a for loop, is a great opportunity to show how “seven plus or minus two” connects to programming. Once we have figured out how to do something moderately complicated, we make it re-usable and give it a name so that it only takes up one slot in working memory rather than several. It is also a good opportunity to talk about exploratory programming: rather than designing a program up front, we can do a few useful things and then retroactively decide which are worth encapsulating for future re-use.
shellscripting  unix  linux  shell  bash  butwhy  programming  sevenplusorminustwo  teaching  workshop  reference  advice  bestpractices 
february 2019 by kme
rgaiacs/swc-shell-split-window: Script to split the shell using tmux | https://github.com/
Script to split the shell using tmux. Contribute to rgaiacs/swc-shell-split-window development by creating an account on GitHub.
teaching  unix  shell  shellscripting  workshop  utility  software  tmux 
february 2019 by kme
bash - Set and Shopt - Why Two? - Unix & Linux Stack Exchange | https://unix.stackexchange.com/
The difference is in the changed environment variable used by bash. Setting with the set command results in $SHELLOPTS. Setting with the shopt command results in $BASHOPTS.
bourne  bash  shell  configfile  configuration  history  butwhy  explained 
february 2019 by kme
linux - bash: variable name not being expanded with Tab completion - Super User | https://superuser.com/
shopt -s direxpand will make echo $HOME/<tab> expand to echo /home/matt/ in bash 4.2. In bash 4.1 it should be the default.
bash  tabcompletion  bashcompletion  commandline  shell  configfile  essential  movein  annoyance  solution  fuckina 
february 2019 by kme
ingydotnet/...: Dot Dot Dot | https://github.com/
Dot Dot Dot. Contribute to ingydotnet/... development by creating an account on GitHub.
dotfiles  configfiles  bash  shell 
january 2019 by kme
shocco.sh | https://rtomayko.github.io/
Interesting technique for generating a '--help' usage message:

<code class="language-bash">
# This is the second part of the usage message technique: `grep` yourself
# for the usage message comment prefix and then cut off the first few
# characters so that everything lines up.
expr -- "$*" : ".*--help" >/dev/null && {
grep '^#/' <"$0" | cut -c4-
exit 0
}
</code>
docco  literateprogramming  documentaiton  shell  bash  shellscripting  library 
october 2017 by kme
terminal - command line method or programmatically add ssh key to github.com user account - Unix & Linux Stack Exchange
Auth with username and password is supported by github api:

There are three ways to authenticate through GitHub API v3. ...
Basic Authentication
$ curl -u "username" https://api.github.com
...

So just choose a lib in the language you prefer and use the implemented version of the Create a Public Key "Public Key" API Section:

Creates a public key. Requires that you are authenticated via Basic Auth, or OAuth with at least [write:public_key] scope.

INPUT
POST /user/keys

{
"title": "octocat@octomac",
"key": "ssh-rsa AAA..."
}

If you want to use it from command line (via curl):

curl -u "username" --data '{"title":"test-key","key":"ssh-rsa AAA..."}' https://api.github.com/user/keys
github  api  shell  commandline  publickeyauthentication  solution 
august 2017 by kme
How do I redirect command output to vim in bash? - Ask Ubuntu


You can use process substitution (this also works with applications that can't read from STDIN):

vim <(ls -la)

Or use vim's function to read from STDIN:

ls -la | vim -

vim  processsubstitution  bash  shell  cli  commandline  shellscripting  pipeline  pipes  solution 
april 2017 by kme
options - Is there some way to echo from terminal into new vim buffer - Vi and Vim Stack Exchange
This is not a duplicate, and the other linked posts do not answer the question asked here.
vim  pipeline  pipe  shellscripting  bash  shell  needshelp 
april 2017 by kme
Cut off file at the tail and head
I got the same error message ("from: can't read /var/mail/lxml") when I forgot to include the shebang in a python script, because 'from' exists as a binary on Unix systems and prints the names of senders in your mail spool.

If you have 'import' lines above that, they'll just hang waiting to communicate with the X server, since 'import' (part of ImageMagick) "saves any visible window on an X server and outputs it as an image file."
python  shellscriptping  shell  bash  errormessage  solution 
april 2017 by kme
bash XHTML parsing using xpath - Stack Overflow
I think maybe 'xpath' comes with the Perl XML::Parser library. Not sure.
shell  commandline  bash  shellscripting  xml  parser 
april 2017 by kme
dd - How do I create a 1GB random file in Linux? - Super User
@PeanutsMonkey: Right; you would need something like dd if=/dev/urandom bs=750M count=1 | uuencode my_sample > sample.txt. – Scott Sep 6 '12 at 19:33
webmaster  sysadmin  testing  random  data  generator  shellscript  bash  shell  solution 
january 2017 by kme
How to install autojump for Fish – Code Yarns

Source the autojump.fish file in your fish configuration, by opening the file ~/.config/fish/config.fish in an editor and adding these lines:

1
2
3
4
5
6

begin
set --local AUTOJUMP_PATH $HOME/.autojump/share/autojump/autojump.fish
if test -e $AUTOJUMP_PATH
source $AUTOJUMP_PATH
end
end
fish  autojump  shell  configfile  dotfiles  solution 
january 2017 by kme
Trying to sort on two fields, second then first - Unix & Linux Stack Exchange


A key specification like -k2 means to take all the fields from 2 to the end of the line into account. So Villamor 44 ends up before Villamor 50. Since these two are not equal, the first comparison in sort -k2 -k1 is enough to discriminate these two lines, and the second sort key -k1 is not invoked. If the two Villamors had had the same age, -k1 would have caused them to be sorted by first name.

To sort by a single column, use -k2,2 as the key specification. This means to use the fields from #2 to #2, i.e. only the second field.

sort -k2 -k3 <people.txt is redundant: it's equivalent to sort -k2 <people.txt. To sort by last names, then first names, then age, run

sort -k2,2 -k1,1 <people.txt

or equivalently sort -k2,2 -k1 <people.txt since there are only these three fields and the separators are the same. In fact, you will get the same effect from sort -k2,2 <people.txt, because sort uses the whole line as a last resort when all the keys in a subset of lines are identical.


The '-s' (stable sort) option for GNU sort is interesting; maybe someday I'll understand what it's for.
@manatwork That should not be necessary; if all the specified fields compare equal, sort will compare the entire line. Or with GNU sort you can use -s for stable sort. – augurar Mar 2 '15 at 19:08
unix  shell  bash  sorting  textprocessing  dammitbrain  fuckina  explained  solution 
december 2016 by kme
command line - sponge from moreutils - what's the difference to shell redirect? useful examples? - Unix & Linux Stack Exchange
But how do you make changes to input? With standard POSIX toolchest, you need to use a temporary file, some thing like:

grep -v '^#' input >/tmp/input.tmp
mv /tmp/input.tmp ./input

With shell redirection:

grep -v '^#' input >input

will truncate input before you reading from it.

With sponge, you can:

grep -v '^#' input | sponge input
bash  shell  shellscripting  pipes  redirection  dammitbrain  movein  essential  reference 
december 2016 by kme
« earlier      
per page:    204080120160

Copy this bookmark:





to read