How to count all the lines of code in a directory recursively?

Bash
We've got a PHP application and want to count all the lines of code under a specific directory and its subdirectories. We don't need to ignore commen...
4 years ago

Shell equivalent to "try/except" in Python?

Bash
I'm cleaning the output of my scripts. For example: rm -f ./file No such file or directory So, I need something like the try/except in python....
4 years ago

Subtract 2 variables in Bash

Bash
I have the script below to subtract the counts of files between 2 directories but the COUNT= expression does not work, what is the correct syntax? #!...
4 years ago

awk : parse and write to another file

Bash
I have records in XML file like below. I need to search for <keyword>SEARCH</keyword> and if present then I need to take the entire recor...
4 years ago

Stray newline in file redirect

Bash
I have a batch script with the following two lines in it. svnversion . > myversion.txt set /p MyVersion=<myversion.txt This has always worked...
4 years ago

Convert decimal to hexadecimal in UNIX shell script

Bash
In a UNIX shell script, what can I use to convert decimal numbers into hexadecimal? I thought od would do the trick, but it's not realizing I'm feedi...
4 years ago

How to tar a directory from different - different server and copy to current server on which I am working

Bash
Actually I want to tar a directory from different-different server and need to move that tar to my current server on which I am working so I am writin...
4 years ago

Bash command to see if any files in dir - test if a directory is empty

Bash
I have the following bash script: if ls /Users/david/Desktop/empty > /dev/null then echo 'yes -- files' else echo 'no -- files' fi How w...
4 years ago

How to use variable in sed search pattern

Bash
I will show an example to explain my problem. VARIABLE='some string' I want to search the string in file like: sed -n "/$VARIABLE,test/p" aFile ...
4 years ago

What does “-z” does exactly in a shell script?

Bash
I have got this script,I know what is happening in the first line and the if block, but cant understand the if condition. pid5=$(ps aux | grep -w "c...
4 years ago

Bash: declaring global variable inside a function

Bash
What I want to do is following. Inside a function, I need to assign a value to a variable, whose name is taken from another variable. In other words: ...
4 years ago

How to declare and use boolean variables in shell script?

Bash
I tried to declare a boolean variable in a shell script using the following syntax: variable=$false variable=$true Is this correct? Also, if I wan...
4 years ago

Delete All Except One Python

Bash
I have folder with full off different file extensions like : xyz.bue , aks.eu , ejz.ff etc. I would like to have a script or a line of code that delet...
4 years ago

error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token

Bash
I am working on a simple shell project and i had the main loop working. I could input commands and it would parse the string. I also had a which comm...
4 years ago

View exit code of a program (After the program exited)

Bash
Lets say a program that outputs a zero in case of success, or 1 in case of failure, like this: main () { if (task_success()) return 0; ...
4 years ago

Parse hocon file using shell script

Bash
I have one hocon configuration created from JSON file. I need to parse the following hocon and extract the values sample hocon file: sample.json ...
4 years ago

Permission denied when I try to open the browser and a specific URL from shell

Bash
I would like to open the browser(no matter which), and browse a specific website, say, youtube.com. And I'd like to run it from a .sh file. I have tr...
4 years ago

Unix shell: get each header of a file in one line

Bash
Let us have a file whose headers are of the form: head_name_1 head_name_2 head_name_3 ... head_name_N Assume that the delimiter is a tab (so we don...
4 years ago

source all files in a directory from .bash_profile

Bash
I need to allow several applications to append to a system variable ($PYTHONPATH in this case). I'm thinking of designating a directory where each app...
4 years ago

Assign return value of DB2 query to variable

Bash
I have a file test.sh in which i have a query which gives me the count of total records in the table, as shown below: Query: echo db2 -x "select ...
4 years ago