scripting – performance improvement with file open

2020-04-20 2 min read Bash Learning Linux

Sometimes just one line of code can make all the difference. I will show you with example.

 

Here is script with 2 functions. Both are writing some lines of text to a file. First function, “a” I have used the redirection to write to file. Function “b”, I have opened a file descriptor with “>” before going into the loop and use that reference for writing to the file. (This concept remains same for any scripting or programming language).

Continue reading

ShellCheck – check basic POSIX shell script errors

2015-08-03 1 min read Bash Fedora

Here is description of the tool:

Description : The goals of ShellCheck are:
  • To point out and clarify typical beginner’s syntax issues,
    :   that causes a shell to give cryptic error messages.
  • To point out and clarify typical intermediate level semantic
    :   problems, that causes a shell to behave strangely and
    :   counter-intuitively.
  • To point out subtle caveats, corner cases and pitfalls, that may
    :   cause an advanced user’s otherwise working script to fail under
    :   future circumstances.

To install

Continue reading

Paste clipboard is bash or shell scripts with modification.

2010-07-20 1 min read Bash Linux

Today I had a issue where I wanted to paste the clipboard to a shell script after removing the spaces. So, I went hunting for a way to do this. Finally I came up with this:

sudo yum install xclip

Then you can paste the clipboard content using ”xclip -o”. So now the problem is reduced to selecting the required info and doing :

xclip -o |sed ’s/ //g’

or

Continue reading