Register a domain and help support LQ
Go Back > Blogs
User Name



Make a bash script recognize bash aliases

Posted 05-12-2015 at 05:16 PM by the dsc (linux-related notes)
Updated 05-12-2015 at 05:22 PM by the dsc (mismatched tags)

Say, if you have a script that would take as a parameter something that you have aliased, it wouldn't work.

I mean:

$ ./ myalias whatever else
/home/dude/scripts/ line 3: myalias: command not found

In order to make it work, the said script must include:

shopt -s expand_aliases
source ~/.bash_aliases
(Or wherever your aliases are set, which would preferably be...
Posted in Uncategorized
Views 317 Comments 0 the dsc is offline

[bash] "keep trying" command, even if exits with error, for at least 10 times

Posted 08-08-2014 at 11:40 PM by the dsc (linux-related notes)
Updated 08-08-2014 at 11:42 PM by the dsc
Tags bash

A script that tries to run a given arbitrary command N times, or until it exits with success. The commented parts are aborted attempts to make it figure whether the first parameter is a number instead of a command, and that would be used as the maximum number of attempts. Something went wrong, sometime I'll try to figure it out.

# this program is stupid. It's declared to be in public domain by its author, who whishes to remain anonymous
Posted in Uncategorized
Views 341 Comments 3 the dsc is offline

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

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

Originally Posted by cfajohnson
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 ]
echo "------------"

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):

if [ ${j:-0} -lt 50 ]
Posted in Uncategorized
Views 516 Comments 0 the dsc is offline
Rating: 2 votes, 5.00 average.

Bash Scripting for Dummies and Geniuses

Posted 11-20-2013 at 10:18 AM by rtmistler
Updated 06-17-2014 at 02:25 PM by rtmistler

One only need look at 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:

"All programming is the use of simple operations to solve complex
Senior Member
Posted in Bash Scripting
Views 1019 Comments 3 rtmistler is offline

Run C/C++ Code As Script

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

runc update Sept 27, 2013

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.

Posted in Uncategorized
Views 713 Comments 0 rainbowsally is offline


All times are GMT -5. The time now is 02:40 AM.

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