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

learn more… | top users | synonyms (2)

5
votes
3answers
261 views

How can I make a script take multiple arguments?

This is a very simple script #!/usr/local/bin/bash set -e if [ "$#" -lt 1 ] then echo "Please insert at least one argument" exit else echo -e "\c" fi if [ -h "$1" ] then echo "$1 is a ...
3
votes
2answers
286 views

How to print out only the script name?

[username@notebook ~]$ cat foo.sh #!/bin/bash echo "$0" [username@notebook ~]$ ./foo.sh ./foo.sh [username@notebook ~]$ Question: How can I output the "foo.sh"? No matter how was it executed.
0
votes
2answers
26 views

Add some text while output to file

Assume I have this command: ./clang-$j.out >> clang-result.txt and the each output for clang-$j.out is a fixed-length hash value (each program per line), however, I want to distinguish them by ...
0
votes
0answers
26 views

compare dynamic file [on hold]

I have a list of file that will be updated each hour and the name given to these file is according to the date and the hour for example: list_hour_date.txt list_9_20042015.txt list_10_20042015.txt ...
1
vote
1answer
24 views

How to run a shell script (bash) on a chromebook?

I have a shell script and I need to run it in order to connect to a remote ubuntu linux machine having encrypted HDD, in order to enter the passphrase. There's a shell script for this, but I have a ...
1
vote
1answer
20 views

Need a shell script for copying files that have long and out of capacity names

I have a directory on a NTFS file system which contains files with short and long names, I entered copy command for that directory to be copied on a Ext2 file system, files with short names copied ...
1
vote
3answers
58 views

How to copy lines from multiple files into one new file and keep file name?

I have 81 files in .fasta format that contain (up to) 53 items. Such as: /User/MyData/Sample_1.fasta /User/MyData/Sample_2.fasta .... /User/MyData/Sample_81.fasta Each .fasta file contains a name ...
3
votes
3answers
97 views

dash: parse string into two variables

I have a dash script, and I need to parse $1, which is a string containing two parts separated by ':', such as foo:123. I would like to to save foo in $X and 123 in $Y. I thought I could use read: $ ...
-2
votes
1answer
54 views

How to create a script that merges two files to get a specific output in the korn shell? [duplicate]

I'm currently working on trying to merge two files together on unix and I REALLY need help. I'm very new to Unix (and this site) and would appreciate any assistance. first file: Tom 313.455.6786 ...
2
votes
1answer
59 views

How can I check if rsync made any changes in bash?

I have a script which uses rsync to sync data in a remote -> local scenario. Immediately after the rsync command is run, a check to see if the error code equals zero or not. If its zero, further ...
1
vote
0answers
27 views

Why can't Firefox open a link with a shell script that uses `source`?

I am attempting to use GRC's SQRL client in Wine, using this shell script to launch it. I have a couple helper scripts that I source, in order to reduce code duplication. An example of one such ...
1
vote
1answer
17 views

Get the time when nohup R program finishes

I want to get the time when program finish. But it always show the same time. Here is my shell script. But it always show that START TIME is same as END TIME. START=$(date +"%r") nohup Rscript ...
0
votes
1answer
21 views

Persistence Bash history between detached processes

I haven't yet been able to find this among the bash documentation so I was hoping it could get answered if I asked it here. Is there any way that I can, on execution of a script, branch its history ...
1
vote
0answers
22 views

How do I process new additions to logs

I know that I can use a few tools like tail and less to view the newest additions to a growing log file. What I want to do, though, is run some sort of script at regular intervals (like cron) on the ...
0
votes
0answers
56 views

Assistance with script on multiple hosts [on hold]

I am running the below script on Server A. Before running this I read the following link: Generate an RSA key pair for version 2 of the SSH protocol #!/bin/bash HOSTS="serverA, serverB" ...
5
votes
3answers
219 views

Is it possible to echo into a file, but use indenting in the shell script source? [duplicate]

If I have some nested and indented statements that echo a multi-line string into a file, the indents from the original shell (in my case bash) will be carried over into the target file. To avoid ...
1
vote
3answers
51 views

Last exit status from within script without source

Supposing someone invokes a non-existent command, the only way I know to retrieve its error status from a script I execute right after is by using source I.e., let's say this script's name is dummy ...
0
votes
1answer
24 views

Run script from GUI with terminal output

I would like to run a script from the GUI. For example a simple echo "hello" from the right click context menu. In my case I would set up an action in thunar like this: Then it appears in the ...
4
votes
3answers
102 views

Redirect the tail output to a file then stop when match found

there is this log file that data coming in is continuous. what i wanted to happen is to tail -f this log file then redirect it to a file with the ff conditions example of the log files content ...
0
votes
1answer
21 views

assistance with scripting list of users

I'm new to scripting, so far I've created this: #!/bin/sh ( echo List of users in PRD echo $(date) cat /etc/passwd | awk -F: '{print $1,$3,$5}' | sort | \ while read username uid gecos do echo ...
-1
votes
0answers
30 views

Shell script for electrum - how to add the seed? [on hold]

I use a diskless web server with a live cd and looking for a possibility to restore my electrum wallets automatically by a seed. I would like to implement a script that performs this task for me. so ...
0
votes
0answers
20 views

URL Parameters with cURL code

I have been converting a .vbs script for use with CURL from an old domain to a new AD domain, and to post to a new sharepoint. I think I have evenrything correct except my destination. My output log ...
0
votes
0answers
20 views

output in columns [duplicate]

i am trying to put my data after a snmp walk in a table this is my code: for i in `cat $Rep_Scripts/IP_ALU_LIST.txt | awk '{print}'` do read hostname ip <<< $(echo $i |sed 's/;/ /') ...
19
votes
2answers
2k views

What's the point in redirecting output of grep to /dev/null?

Consider this line: ${libdir}/bin/licenseTool check "${SERIAL}" "${VERSION}" "${PRODUCT}" ${libdir} | grep '^200' >/dev/null What's the point of looking for the pattern in the output if the ...
0
votes
1answer
40 views

Add the number in the column if exists

I need to count Nodes_Util for each Queue. In the example below, queue1 has only one line, but it varies and it could be nothing sometimes and it applies to all queues. I want to dynamically add the ...
2
votes
2answers
34 views

how to strip the last slash of the directory path?

I have a script which requires an directory as one argument. I want to support the two form: one is like a/b/c (no slash at the end) and another is like a/b/c/ (has slash at the end). My ...
0
votes
1answer
36 views

How do I copy all files that have been created or modified in the last 12 months?

I would like to copy all the files created in the last 12 months to a new folder leaving behind everything else. Including sub folders.
2
votes
1answer
25 views

How to download a lot of documents on the terminal from a server?

I have to write a bash script (.sh) with less than 300 characters which downloads all of the genomes 22 in this server ftp://ftp.ncbi.nih.gov/genomes/Homo_sapiens/ (the ones with fa.gz extention) and ...
2
votes
3answers
33 views

Extract a part of a string in a bash script

I have a variable with some text in it. I need to get a specific bit of information out of it. For example I have export OUTPUT="Running \"protractor:admin\" (protractor) task Using ChromeDriver ...
2
votes
1answer
26 views

I have a multi-line string that I need to iterate over, but I'm not using bash. Advice?

I'm using Dash because this is to run on my rPi. Bash is not an option. I'm rewriting a Bash script to work with Dash. I'm hoping to make it as POSIX-compliant (portable) as possible. The thing is ...
1
vote
1answer
35 views

How do I capture output into a variable and still have it goto the screen too?

I can do OUTPUT=$(grunt test) and that puts the output into OUTPUT but it's no longer on the screen. I need to see the output as it comes as well, so I can't just wait and then echo $OUTPUT. How can ...
1
vote
0answers
11 views

Issues while eMMC partitioned using sfdisk

I am writing firmware(MLO,u-boot.img, uImage(ver 3.12), dtb, rootfs.tar.gz) programming script for am335x based custom board. Rootfile system is to be put onto the eMMC. Firmware programming script ...
0
votes
0answers
32 views

How to use a printf in awk with a delimiter? [closed]

awk -F, 'BEGIN { printf "%2s %5s %5s", $1, " ", $2 }' file1 >> file2 How would this display, my thinking is that this would bring back: file1 has: 40,Car 50,Truck 60,Van file2 has: 40 ...
2
votes
4answers
104 views

How to combine two files into one with columns for each file's data? [duplicate]

I have two files: file1 contains: 1 2 3 4 file2 contains: John Sam George Ken I want to combine these files to create one file(file3) 1, John 2, Sam 3, George 4, Ken My thought was to use ...
2
votes
2answers
56 views

Joining bash arguments into single string with spaces

I'm trying to join all of the arguments to a Bash function into one single string with spaces separating each argument. I also need to have the string include single quotes around the whole string. ...
1
vote
1answer
19 views

Unable to replace variable in shell script using awk

I have been struggling to replace every occurence of "<KEY>" in a file with ${encryptedkeyValue} I wrote this line but it is not doing ...
1
vote
1answer
28 views

How to retrive a file from a prompt?

Suppose I wanted to create a script that would prompt for a file to be search for. Such that, echo "What file are you searching for?" read filename filepath=/test/dir1 file=$filename for I in file ...
1
vote
2answers
17 views

How to check if a group of files is readable?

I have to check if a group of files is readable. I know how I would go about checking one file by using [ -r file.txt ], but how would I go about writing a loop that would check multiple files ...
0
votes
4answers
42 views

Getting an error when running awk from a script

I have a file some.txt -rwxrw-r-- 1 ivamshky ivamshky 152 Apr 2 00:42 12.sh~ -rw-rw-r-- 1 ivamshky ivamshky 58 Apr 6 19:03 a.c -rw-rw-r-- 1 ivamshky ivamshky 98 Apr 1 20:27 all.sh ...
0
votes
2answers
59 views

Having trouble with basic if then statement

learning the basics of scripting and I have this line of code: #!/bin/sh if [ $# -ne 1] then echo "Please provide one directory to search" echo "Example usage: something.sh directory_name" ...
1
vote
1answer
34 views

Variables in dialog radiolist

I have the following dialog radiolist, which works fine. #!/bin/bash ch1a="1" ch1b="Fri, 20/3/15" ch2a="2" ch2b="Sun, 21/6/15" ch1="\"$ch1a\" \"$ch1b\"" dialog --title "Equinoxes and Solistices" \ ...
-2
votes
0answers
37 views

how to print only part of line using awk/sed/grep [closed]

I need to print only part of the complete line after removing/omitting starting part. Can someone give me the regular expression to do so
3
votes
3answers
43 views

How to check if string is blank in tcsh

How can I check whether a string is empty in tcsh? Before you freak out, no I'm not writing shell scripts with tcsh. I am asking because I want to use this in my .tcshrc file. Specifically, I want ...
1
vote
2answers
38 views

CentOS 7 shell script interpretor

I am starting to write a shell script to be run in CentOS 7. Which interpreter should it call, and what should the shebang line look like? I tried this: #!/bin/sh But when I type cd /bin ...
2
votes
1answer
46 views

How to I prevent exec from keeping the script running?

I'm using exec like this: #!/bin/bash exec > >(tee /tmp/mylog.log) 2>&1 bash -c 'sleep 12312' & I want the output of the commands to be in a log file, and then I want to start a ...
3
votes
2answers
127 views

How to check if vim is installed?

I want to know how to check whether a command is installed. Specifically, I want to alias vi to vim on all machines where vim is a valid command. And I want to keep my *rc files generic. But some ...
3
votes
2answers
96 views

sed insert in the beginning of multiple files is not working

I came across a lot of answers, including theses: sed on OSX insert at a certain line http://stackoverflow.com/questions/14846304/sed-command-error-on-macos-x ...
1
vote
1answer
72 views

How to merge two files in the same row?

I have two files. file1: Dave 734.838.9800 Bob 313.123.4567 Carol 248.344.5576 Mary 313.449.1390 Ted 248.496.2204 Alice 616.556.4458 file2: Bob Tuesday Carol Monday Ted Sunday ...
2
votes
3answers
120 views

How to filter some files out of my directory?

I have some files in my directory. They can be classified into two categories: the files' name pattern in class one are like 1000-24-1-7-1 that have five numbers separated by four dash; the files' ...
3
votes
1answer
16 views

Find repository names from gitolite info output

How do I extract the names from the gitolite info command output, for further piping into a script? I'm writing a migration script to migrate all my repositories from gitolite to a Gitlab server. ...