Commands tagged declare (4)

  • no need to reinvent the wheel. Thanks to the OP for the "obsolete" hint. 'declare' may come in pretty handy on systems paranoid about "up-to-dateness" Show Sample Output


    3
    typeset -f <function name>; declare -f <function name>
    unefunge · 2010-11-24 15:59:42 13
  • 5 helpful aliases for using the which utility, specifically for the GNU which (2.16 tested) that is included in coreutils. Which is run first for a command. Same as type builtin minus verbosity alias which='{ command alias; command declare -f; } | command which --read-functions --read-alias' Which (a)lias alias whicha='command alias | command which --read-alias' Which (f)unction alias whichf='command declare -f | command which --read-functions' Which e(x)ecutable file in PATH alias whichx='command which' Which (all) alias, function, builtin, and files in PATH alias whichall='{ command alias; command declare -f; } | command which --read-functions --read-alias -a' # From my .bash_profile http://www.askapache.com/linux-unix/bash_profile-functions-advanced-shell.html Show Sample Output


    2
    alias whichall='{ command alias; command declare -f; } | command which --read-functions --read-alias -a'
    AskApache · 2010-11-18 03:32:04 7
  • I was looking for the fastest way to create a bunch of ansi escapes for use in echo -e commands throughout a lot of my shell scripts. This is what I came up with, and I actually stick that loop command in a function and then just call that at the beginning of my scripts to not clutter the environment with these escape codes, which can wreck havok on my terminal when I'm dumping the environment. More of a cool way to store escape ansi codes in an array. You can echo them like: echo -e "${CC[15]}This text is black on bright green background." I usually just use with a function: # setup_colors - Adds colors to array CC for global use # 30 - Black, 31 - Red, 32 - Green, 33 - Yellow, 34 - Blue, 35 - Magenta, 36 - Blue/Green, 37 - White, 30/42 - Black on Green '30\;42' function setup_colors(){ declare -ax CC; for i in `seq 0 7`;do ii=$(($i+7));CC[$i]="\033[1;3${i}m";CC[$ii]="\033[0;3${i}m";done;CC[15]="\033[30;42m"; export R='\033[0;00m';export X="\033[1;37m"; }; export -f setup_colors CC[15] has a background of bright green which is why it is separate. R resets everything, and X is my default font of bright white. CC[15]="\033[30;42m"; R=$'\033[0;00m'; X=$'\033[1;37m' Those are just my favorite colors that I often use in my scripts. You can test which colors by running for i in $(seq 0 $((${#CC[@]} - 1))); do echo -e "${CC[$i]}[$i]\n$R"; done See: http://www.askapache.com/linux-unix/bash_profile-functions-advanced-shell.html for more usage. Show Sample Output


    1
    declare -ax CC; for i in `seq 0 7`;do ii=$(($i+7)); CC[$i]="\033[1;3${i}m"; CC[$ii]="\033[0;3${i}m"; done
    AskApache · 2009-09-21 07:00:55 8
  • Normally the bash builtin command 'set' displays all vars and functions. This just shows the vars. Useful if you want to see different output then env or declare or export. Alias 'sete' shows sets variables alias sete='set|sed -n "/^`declare -F|sed -n "s/^declare -f \(.*\)/\1 ()/p;q"`/q;p"' Alias setf shows the functions. alias setf='set|sed -n "/^`declare -F|sed -n "s/^declare -f \(.*\)/\1 ()/p;q"`/,\$p"' Also see: http://www.commandlinefu.com/commands/view/6899/print-all-environment-variables-including-hidden-ones At the very least, some cool sed commands! From my .bash_profile http://www.askapache.com/linux-unix/bash_profile-functions-advanced-shell.html Show Sample Output


    0
    alias sete='set|sed -n "/^`declare -F|sed -n "s/^declare -f \(.*\)/\1 ()/p;q"`/q;p"'
    AskApache · 2010-11-17 23:58:01 10

What's this?

commandlinefu.com is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.

Share Your Commands


Check These Out

Use a Gmail virtual disk (GmailFS) on Ubuntu
Packages: gmailfs fuse-utils libfuse2 gvfs-fuse Config files: /etc/gmailfs/gmailfs.conf; ~/.gmailfs.conf (make a copy from the another one) Unmount: $ fusermount -u /mount/path/ /etc/fstab (Optional): none /mount/path/ gmailfs noauto,user[,username=USERNAME,password=PASSWORD,fsname=VOLUME] 0 0 NOTES: - The options between [] are optional since they already setuped on the config files. - The '-p' flag shows a prompt for the password entry. - It's necessary to add the user to the 'fuse' group. You can do that with: $ sudo chgrp fuse /dev/fuse and $ sudo usermod -a -G fuse USER - The volume name is not needed but highly recommended to avoid file corruption. Also choose a non-trivial name. - Google doesn't approve the use of Gmail account other than e-mail purposes. So, I recommend the creation of a new account for this.

Check Ram Speed and Type in Linux
from http://maysayadkaba.blogspot.com/2008/08/linux-check-ram-speed-and-type.html

Release memory used by the Linux kernel on caches
=1 --> to free pagecache =2 --> to free dentries and inodes =3 --> to free pagecache, dentries and inodes

Shrink more than one blank lines to one in VIM.

Check if you work on a virtual/physical machine in Linux
Command used to know if we are working on a virtual or physical machine. This command will use the dmidecode utility to retrieve hardware information of your computer via the BIOS. Run this command as root or with sudo.

need ascii art pictures for you readme text ?
Require boxes and / or cowsay packages. After input boxes -d dog , type your text and then press ctrl + d . Same goes for cowsay .

video thumbnail gallery
thumbnail gallery of video using totem

statistics in one line
In this example, file contains five columns where first column is text. Variance is calculated for columns 2 - 5 by using perl module Statistics::Descriptive. There are many more statistical functions available in the module.

Print one . instead of each line
If you're running a command with a lot of output, this serves as a simple progress indicator. This avoids the need to use `/dev/null` for silencing. It works for any command that outputs lines, updates live (`fflush` avoids buffering), and is simple to understand.

Terminal Escape Code Zen - Strace and Tput
Depending on the TERM, the terminfo version, ncurses version, etc.. you may be using a varied assortment of terminal escape codes. With this command you can easily find out exactly what is going on.. This is terminal escape zen! $ ( 2>&2 strace -f -F -e write -s 1000 sh -c 'echo -e "initc\nis2\ncnorm\nrmso\nsgr0" | tput -S' 2>&1 ) | grep -o '"\\[^"]*"' --color=always "\33]4;%p1%d;rgb:%p2%{255}%*%{1000}%/%2.2X/%p3%{255}%*%{1000}%/%2.2X/%p4%{255}%*%{1000}%/%2.2X\33\\\33[!p\33[?3;4l\33[4l\33>\33[?12l\33[?25h\33[27m\33(B\33[m" Lets say you want to find out what you need to echo in order to get the text to blink.. $ echo -e "`tput blink`This will blink`tput sgr0` This wont" Now you can use this function instead of calling tput (tput is much smarter for portable code because it works differently depending on the current TERM, and tput -T anyterm works too.) to turn that echo into a much faster executing code. tput queries files, opens files, etc.. but echo is very strait and narrow. So now you can do this: $ echo -e "\33[5mThis will blink\33(B\33[m This wont" More at http://www.askapache.com/linux-unix/bash_profile-functions-advanced-shell.html


Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.

» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10

Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for: