Questions about shell scripts, executable files that are interpreted by a shell (bash, zsh, etc.).

learn more… | top users | synonyms (2)

0
votes
1answer
23 views

Count number of times each line repeats itself, In case Insensitive manner

I have a file like a A b c I want to print number of times each line repeats it self in a case insensitive manner. I found below command to be useful: tr A-Z a-z | uniq -c | sed -e 's/^ *//' -e ...
2
votes
3answers
143 views

find, xargs and mv: renaming files with double-quotes, expansion and bash precedence issue

Ok, I'm simply trying to strip out double-quotes in my filenames. Here's the command I came up with (bash). $ find . -iname "*\"*" -print0 | xargs -0 -I {} mv {} {} | tr -d \" The problem is the ...
-2
votes
1answer
46 views

Sorting a file based on second column in a Tab Spaced file [closed]

This may be a duplicate, But I have a Tab separated file and I need to sort the file based on second column which are float values. sort -s -k2,2gr -t$'\t' The code states it is to sort based on ...
1
vote
3answers
44 views

Evaluation an expression and rounding up to three decimals

I have an expression "5+50*3/20 + (19*2)/7" I need to round it up to 3 decimal places. The answer to this is 17.92857142857143. When I use the script below it is giving me 17.928. The answer should be ...
1
vote
6answers
380 views

Print numbers from 1-50

x=1 while [ $x -le 50 ] do echo $x $x=(($x + 1)) done I have wrote the above code. What seems to be a easy task in many programming languages is giving this error for me. solution.sh: line ...
3
votes
2answers
43 views

Script to replace all symbolic links to a target to point to another target (in the same directory)

Given the following contrived example: $ mkdir -p a/b && touch a/b/original-target && touch a/b/new-target $ mkdir -p c1/c2 && cd c1/c2 && ln -s ...
2
votes
1answer
57 views

Bash variable ${0##*/}

I am trying to understand the variable ${0##*/} that I encountered in a bash script. I understand that $0 contains the name, or the path, of the script, then ## works as in ${parameter##pattern} ...
2
votes
3answers
120 views

Command for finding users who are not logged in

Is there any command that can find the number of users that are not logged into the system ? I am trying to write a shell script that counts the number of users who are logged in and number of users ...
2
votes
5answers
211 views

cd into all directories, execute command on files in that directory, and return to previous current directory

I'm attempting to write a script that will be run in a given directory with many single level sub directories. The script will cd into each of the sub directories, execute a command on the files in ...
4
votes
1answer
148 views

string in a file as a variable

I have a conf file content like below. file.conf: key="name" value="pswd" Now I want write a script to having two variable like above script.sh key="name" #key as variable value="pswd" ...
0
votes
3answers
101 views

Shell script to add or replace block of text?

I'm looking for a shell script (Bash) that adds or replaces copyright text at the beginning of the file (for .c and .h files). It should search and add or replace the copyright text block for all the ...
0
votes
0answers
10 views

Get CPU time for Benchmark in Bash Script

I'm using this Method here: http://giantdorks.org/alain/how-to-benchmark-individual-shell-script-sections-to-identify-slow-parts/ to Benchmark my Bashscript: RuntimePrint() { duration=$(echo ...
1
vote
2answers
35 views

how do I copy files like Microsofts “Robocopy” do in debian?

I've been trying to migrate small parts from my media/download center from windows to linux, before making the jump on my media center. Right now i have a Raspberry pi set up, with raspbian, where i ...
1
vote
0answers
15 views

Pass/Firefox master key integration?

I handle my passwords with pass, and I use the Firefox master password functionality. The master password is rather long and "safe" and stored in pass along with the others. For now, my usual Firefox ...
1
vote
0answers
17 views

remote control of vlc using script over ssh

I'm trying to control vlc video playback on a remote machine using a script and remote ssh. I have machine A, which logs into machine B with this command: # sshpass -p <password> ssh ...
3
votes
1answer
45 views

Use paste with row-major input

I can create a file with multiple columns from a single-column input via paste like this: some_command | paste - - This works when some_command produces the data in column-major format. In other ...
1
vote
2answers
34 views

Paste text to another application from script via shortcut

Let me describe what I want to achieve. We are using two-factor authentication and I would like to create script which will generate TOTP token for me and it will paste it to let's say Firefox on some ...
6
votes
4answers
374 views

Detect if a variable is empty

In my Bash script I have this line: mv -f $HOME_DIR/$dir $HOME_SAVE/BACKUP The problem is when $dir is empty (no $dir directory) the mv command moved the directory $HOME_DIR. We want only to move ...
0
votes
0answers
19 views

Insert values from one database table to other database table through shell scripting in Ubuntu 13.10

I am working with 2 databases say logdb.db and logdb2.db . I have created a table named Original in logdb.db Sqlite database such as follows : CREATE TABLE Original (s_id INT PRIMARY KEY NOT NULL ...
0
votes
5answers
44 views

Is there a way to do a “full file buffering” inside a chain of piped commands?

Very often I do simple operations on a file, for example: cat file1.txt|sed -r 's/^ *//' to remove spaces at the beginning of the line. If I want to overwrite the file, the only way I know is: cat ...
34
votes
1answer
748 views

Security implications of forgetting to quote a variable in bash/POSIX shells

If you've been following unix.stackexchange.com for a while, you should hopefully know by now that leaving a variable unquoted in list context (as in echo $var) in Bourne/POSIX shells (zsh being the ...
1
vote
3answers
40 views

Splitting a string up to a specific location

I have a question and wondering how to address it with sed? How does one cut a variable up to a specific location, in my case _g? Example variable="This_is_good_g0r0s0_continues" I need to cut ...
2
votes
1answer
71 views

Reading two lists containing filenames

I am taking two lists having filenames with paths and using gnu-parallel to process the files from the two lists. However,The command is able to use only files from the first list and not the second ...
0
votes
1answer
19 views

executing commands in shell and turnoff the default displays of commands in console

This is my script cd /opt/product/vinoth -- some operations -- cd - While executing this command cd - the old path get displayed in the console. is there is any way to block this from displaying ...
-1
votes
0answers
23 views

Ping Printer then Execute Command

I have many printers on my network using CUPS and a few pause occasionally. I can't find any consistency between them to isolate the cause so in the meantime I've made a script to view all paused ...
4
votes
2answers
38 views

How do I convert a string into a number interpreted in certain base in bash script?

I'm simply trying to convert a string $RECORD_HDR to a number $RECORD_SIZE, where echo $RECORD_HDR gives 003D and echo $RECORD_SIZE should give 61
0
votes
1answer
58 views

Creating a list containing filenames with paths

I have a directory(INPUTDIR) with sample names as subdirectories(508_C,540_C,570_D etc).Within those each subdirectories there is another directory called FASTQ which contains two kinds of files. ...
0
votes
4answers
55 views

Print last character in the given path

I am trying to concat "comnp.dat_CY*" files into one file. File name, source path and destination path are the parameters. I am trying to find the last character in the path to check if it is "/" or ...
0
votes
0answers
13 views

Simple slide show tool for raw and jpg with playlist

I'm looking for a tool / bash script that can show raws and jpgs from a playlist file in fullscreen. I plan to obtain a list of image file paths and I want to be able to manually navigate from image ...
9
votes
5answers
669 views

Get total duration of video files in a directory

I have a list of .ts files: out1.ts ... out749.ts out8159.ts out8818.ts How can I get the total duration (running time) of all these files?
2
votes
2answers
43 views

Command to work on all files in a folder and output result to single file

I have a list of files, 10 to be exact, in a recipe folder. I must determine the number of occurences of each word in all the files and then order them according to these frequencies. I can get my ...
5
votes
1answer
129 views

How to make a list generated by md5deep in alphabetical order of relative paths?

If I want make a md5sum list recursively, then I would use md5deep, but it starts to pop up some problems such as it won't generate the md5sum file in alphabetical order. For example, $ cd ...
-1
votes
0answers
19 views

how to pass command line arguments from c programm to the bash script? [migrated]

i have written one bash script and now am calling this script from c program. Now i want to pass arguments i.e. argv[1] and argv[2] to the script from command line.
2
votes
2answers
33 views

Checking and Killing processes of a user before deleting

I am working on a script to delete users from text file. However, before deleting, I wanna check if any process by a user is running and if running then kill all the processes and delete. Here's how, ...
1
vote
1answer
24 views

get only file name while iterating over directory instead of path with it [duplicate]

$ script.sh -i /storage/testFile -i stores the path of /storage/testFile/. I want to iterate over file in testFile. Everything goes good, but I want to make this code cleaner and add a directory ...
3
votes
1answer
272 views

How to use printf to show the results of a calculation?

My program is #!/bin/sh printf 'Please enter salary amount: ' read salary TAX="echo $salary * 0.15 | bc" NET="echo $salary + $TAX | bc" printf "Net Salary= %.2f" $NET printf "\n" But whatever I ...
-3
votes
1answer
29 views

How can I apply floating point discounts and taxes in a shell script?

I want to input a number and then add taxes and subtract discounts. I am trying: #!/bin/sh printf "Please enter purchase amount: " read purchase_amount if test $purchase_amount -lt 1000 then ...
1
vote
1answer
60 views

Shell script check if file exists?

I wrote a simple backup script which back ups my stuff on a remote server, everything is working great but I'd like to have some sort of report like "backup successful or not". this is my script # ...
4
votes
3answers
109 views

How to append a date to all files in a directory without touching sub-directories via bash script

I'm currently taking a class for Operating Systems and we're learning to do bash scripts as part of the curriculum. I need to append the date to all the files in a directory without touching ...
1
vote
2answers
43 views

Bash script loop to grow parameters

I want to use whiptail to generate a checkbox list based on the output from another program. Only the first word on each line of the output from the first program is necessary, so I extract it using ...
2
votes
1answer
31 views

'Tar' the result of a 'find', preserving the directory structure

I want to tar all the *.txt file, that I get from the result of a find, that exist into a directory having a tree like this: Directory_name dir1 file1.pdf file1.txt dir2 file2.pdf ...
0
votes
2answers
44 views

for loop not working for multiple lines

I have a array like this "Apple Banana Clementine Date" I have to print like this: 1. Apple 2. Banana 3. Clementine 4. Date Script file: for i in "${fruits[@]}"; do echo "$lineno. $i " ...
1
vote
0answers
34 views

Add entries to an array inside a loop

I am trying to update an array in a linux tcsh script. The script uses a while loop, and I want to add elements to the array every time the loop iterates. Is there a better way to do this? ...
0
votes
2answers
46 views

Why doesn't this pipe command work at this special bash script?

That script test.sh doesn't work after used pipe command. The result shows nothing. Why? #!/bin/bash fun=$( echo $1 ) echo "$fun" commands are as follows, $ echo 1 | ./test.sh
0
votes
1answer
45 views

How to create a script to run several scripts on different servers

I need to automate the execution of several scripts, and I'm writing a script. The scripts have to run concurrently because they are part of a benchmarking suite. I'm trying to execute 6 different ...
2
votes
1answer
23 views

Programatically / dynamically adjust SSH session port forwards

I have a workflow where I am trying to do the following: For a given existing SSH session, access the remote machinne and perform a process from which a port is returned (e.g. a remote daemon has ...
-1
votes
1answer
80 views

Scripting multi-volume (GNU) `tar` with pre-defined number of volumes

I've wrote me a little script to test (or extract) a very big multi-volume tar archive (note: created with GNU tar), each of which 00x.tar chunk will fit onto a standard DVD: #!/bin/bash d=$(dirname ...
0
votes
2answers
26 views

File mapping reference from another file

File1.txt age name city 23 ABC delhi 25 xyz mumbai 12 xxx pune 21 YYY delhi File2.txt city pincode delhi 001 mumabi 002 pune 003 I need to replace city column in file1 with pincode ...
1
vote
2answers
46 views

how to extract path from file location using shell [duplicate]

how to extract path location from below given string. /opt/oracle/app/oracle/product/12.1.0/bin/tnslsnr expected output. /opt/oracle/app/oracle/product/12.1.0/bin (or) ...
0
votes
0answers
27 views

Wifi configuration failed while using shell script

I am trying to configure wireless network in a Linux machine using a shell script. In this shell script, first I am scanning for all nearby available wifi networks with respective details. After that ...