LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Blogs
User Name
Password

Notices


Just annotations of little "how to's", so I know I can find how to do something I've already done when I need to do it again, in case I don't remember anymore, which is not unlikely. Hopefully they can be useful to others, but I can't guarantee that it will work, or that it won't even make things worse.
Old

Give a default/non-null value in order to avoid the "unary operator expected" error

Posted 02-19-2014 at 03:00 PM by the dsc (linux-related notes)
Tags bash

Quote:
Originally Posted by cfajohnson
Quote:
i am trying to compare a value with value 50. but i am getting
"[: -lt: unary operator expected"

I am using

if [ $j -lt 50 ]
then
echo "------------"

fi
Make sure that $j expands to a value. Best is to set it explicitly, but you can also give it a default value (0 in this example):


Code:
if [ ${j:-0} -lt 50 ]
http://www.unix.com/302295072-post3.html...
Member
Posted in Uncategorized
Views 1540 Comments 0 the dsc is offline
Old

A good $PS1 for displaying long paths in the bash prompt

Posted 03-13-2013 at 11:29 PM by the dsc (linux-related notes)
Updated 03-13-2013 at 11:30 PM by the dsc
Tags bash, prompt, ps1

Code:
PS1='${debian_chroot:+($debian_chroot)}\t \u $(if [ ${#PWD} -gt 30 ] ; then myPWD="${PWD:0:12}…/\W" ; myPWD="${myPWD:0:25}…" ; else myPWD=$PWD; fi ; echo $myPWD) $ '
It will display full paths smaller than 30 characters entirely, but for longer paths it will get only the first characters of the whole path, and the fist characters of the last folder in the full path.

The end result is something like:

HH:MM:SS tuxguy /home/tuxguy/mystuf.../xmas...
Member
Posted in Uncategorized
Views 1300 Comments 0 the dsc is offline
Old

Bash quickie: loop N times, without doing math

Posted 10-22-2012 at 09:07 PM by the dsc (linux-related notes)
Updated 03-10-2013 at 12:25 AM by the dsc (improving, varible version)
Tags bash, loop

I thought that the only way to do such type of loop in Bash would require something like "n=$(($n+1))" within the loop, with the loop being conditioned to "n" adding up to whatever you want, such as "until ((n==30)) ; do". But you can actually do "for i in {1..20} ; do <whatever> ; done". That's somewhat similar to Basic's "for i=1 to 20 ; whatever ; next i".

But it won't work with variables for the starting and ending numbers....
Member
Posted in Uncategorized
Views 1703 Comments 0 the dsc is offline
Old

Pseudo-template noob hack that may apply for several situations

Posted 04-12-2012 at 04:10 PM by the dsc (linux-related notes)
Updated 04-12-2012 at 04:14 PM by the dsc

There's a painting software, "mypaint", which is very nice, but it does not support templates, at least not yet.

I've created a template (just a "blank" file with the correct resolution and whatnot) on GIMP, saved it as "ora", but instead of opening this file manually every time, and remembering to save it with a new name in order to not overwrite the template, I came up with a script that will create a new name automatically, with no risk of overwriting...
Member
Posted in Uncategorized
Views 11897 Comments 2 the dsc is offline
Old

"Wait until a process ends, a download ends, or a file conversion ends, then do X"

Posted 08-30-2011 at 03:06 PM by the dsc (linux-related notes)
Updated 08-30-2011 at 09:41 PM by the dsc (a small improvement)

Sometimes you want the computer to shut down after you've finished downloading something or converting some large file into some other format, but you want to go out or go to sleep instead of waiting and checking for it yourself.

For these situations I've come up with two tiny scripts. The first one waits until a file hasn't changed its size on three consecutive intervals of twenty seconds:

Code:
a=0 ; file="$1" ; if [ -f "$file.part" ] ; then file="$file.part"
...
Member
Posted in Uncategorized
Views 1733 Comments 0 the dsc is offline

  



All times are GMT -5. The time now is 12:51 AM.

Main Menu
Advertisement
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration