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

learn more… | top users | synonyms (2)

1
vote
6answers
405 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
52 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
74 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
146 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
270 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
151 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
2answers
166 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
53 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
79 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
20 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
48 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
49 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 ...
2
votes
3answers
55 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
391 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
38 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
55 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 ...
42
votes
1answer
967 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
46 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
78 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
2answers
34 views

executing commands in shell and turnoff the default displays of commands in console [duplicate]

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 ...
4
votes
2answers
44 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
73 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
60 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
16 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
830 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
46 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
143 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 ...
2
votes
2answers
43 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
34 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
317 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
32 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
102 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
137 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
62 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
39 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
49 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
50 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
54 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
52 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
26 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
87 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
28 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
53 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
35 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 ...
1
vote
4answers
234 views

How to delete the files in one folder which are more than 60 days old in UNIX?

I know how to delete the files which are more than 60 days old by modification time, but I want to delete files based on a timestamp in the file name. For example, I have the below files for each day ...
1
vote
5answers
156 views

find the max value of column 1 and print respective record from column 2 from file

How to find the max value from the column 1 and echo the respective path location from a file which contains n number of records. $ cat version.log 112030 /opt/oracle/app/oracle/product/11.2.0 ...
3
votes
1answer
49 views

How to find out the biggest number in many documents that contains different numbers

For example, there are some temperature data at those folders in different time. temps.txt contains the temperature number. So how can I use bash script to find out the maximum temperature? (the ...
1
vote
2answers
53 views

How to get 2 different outcomes from 1 file in unix?

So I'm trying to make a dungeon and I want to have 2 different responses when I enter the one room but I thats as far as I can get. How do I get 2 different outcomes from 1 file? So when you open a ...
0
votes
1answer
62 views

bash script programming question

Why the stomach of cat has ": No such file or directory" ? Help me please! #! /bin/bash if [ $# != 1 ] ; then echo wrong arg,please input one arg exit 1; fi if grep '^[[:digit:]]*$' ...
2
votes
1answer
26 views

Tool to add hierarchical structure to output, similar to tree

Is there a tool that is similar to tree which could be used in conjunction with echo? I want to easily prepend hierarchical structure to output. I know I could write it, but if a solution ("do one ...