LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Blogs
User Name
Password

Notices


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
Rating: 4 votes, 5.00 average.

Bash Scripting for Dummies and Geniuses

Posted 11-20-2013 at 09:18 AM by rtmistler
Updated 05-25-2020 at 08:43 AM by rtmistler

One only need look at LinuxQuestions.org to notice the great amount of script (and code) questions and varieties of comments to realize that we all have varying opinions about bash programming.

Many questions are very complicated, as are the resulting answers and script recommendations. I've noticed that two fundamental points are invariably overlooked by the questioners, and many of the comments:

Quote:
"All programming is the use of simple operations to solve complex
...
Moderator
Posted in Uncategorized
Views 5592 Comments 8 rtmistler is offline
Old

Run C/C++ Code As Script

Posted 09-04-2013 at 11:36 AM by rainbowsally
Updated 08-06-2014 at 07:13 AM by rainbowsally (new version)

runc update Sept 27, 2013

http://rainbowsally.org/rainbowsally...-rs-1.2.tar.gz

Changes slist_count() to standard objlist syntax and removes slist_getCount()
Removes destructor functions from objlist so that each class explicitly free anything memory they allocate.
Added atexit() function to tmpmem/tmpstr functions.
Most of these changes address memory leaks and/or memory that remains accessible after the apps close.

--------------...
Member
Posted in Uncategorized
Views 1365 Comments 0 rainbowsally is offline
Old

bash read file

Posted 05-24-2013 at 09:20 AM by NullTerminator
Updated 05-24-2013 at 11:26 AM by NullTerminator

Sample of while loop to process input
Code:
#!/bin/sh
##################################
# Purpose: Cleanup any confirmation reports (*.pdf) older than xx days
# Called By:  batch daily cleanup process,  /Applications/xyz/distributor.sh
# Author: jeb
# Date: 4/20/07
# Comments: The while loop is preferred over the find -exec rm {} syntax because it
#           does not spawn a process for each file to be deleted.
#           The script expects
...
LQ Newbie
Posted in Uncategorized
Views 1436 Comments 0 NullTerminator 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

  



All times are GMT -5. The time now is 08:53 PM.

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