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

learn more… | top users | synonyms (2)

0
votes
0answers
10 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. When I call my script ...
0
votes
0answers
10 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 ...
45
votes
2answers
1k 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 ...
0
votes
0answers
10 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 ...
4
votes
3answers
87 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 ...
1
vote
3answers
48 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
0answers
15 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
48 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" ...
4
votes
3answers
208 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 ...
18
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 ...
7
votes
5answers
3k views

Exit Google Chrome from terminal

Is there a way to cause google-chrome to quit, from the terminal, besides using killall google-chrome? I would like to be able to close it from a script without killing it.
4
votes
2answers
567 views

How do I run a script when I switch between keyboard layouts

I use more than one keyboard layout, and I would like to find a way to run a script when I switch between them. Is this possible? So far, I can assign a shortcut for a script like this: #!/bin/bash ...
-1
votes
0answers
29 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
1answer
23 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 ...
12
votes
9answers
37k views

How to compare two dates in a shell

How to compare two dates in a shell script? For example something like todate=2013-07-18 cond=2013-07-15 if [ $todate -ge $cond ]; then break fi It doesn't work. ...
4
votes
3answers
11k views

Recovered deleted files on Mac by command line

I accidentally deleted a file by running: rm -rf ./Desktop/myScript.sh I think it's possible to recover the file, because the rm command removes temporarily. How can I recover the deleted file on ...
0
votes
1answer
36 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 ...
18
votes
4answers
40k views

Shell script fails: Syntax error: “(” unexpected

I've been working on a script that automates setting up a development environment for Raspberry Pi development (step by step details that work are here). The script is linked in that article but ...
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
35 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 ...
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 ...
0
votes
0answers
17 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
18 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/;/ /') ...
2
votes
1answer
25 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 ...
2
votes
3answers
32 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 ...
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
10 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
31 views

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

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
102 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 ...
0
votes
4answers
889 views

How to get data count between two strings with multiple occurences in the same file

I have the data in my file as START-OF-FIELDS ID NAME DEPT END-OF-FIELDS START-OF-DATA 1|joy|cs 2|sam|ec END-OF-DATA START-OF-FIELDS ID NAME DOB DEPT ADDRESS END-OF-FIELDS START-OF-DATA ...
2
votes
2answers
52 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. ...
0
votes
2answers
58 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
2answers
16 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 ...
1
vote
1answer
17 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 ...
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 ...
0
votes
4answers
40 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 ...
1
vote
1answer
27 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
3answers
118 views

Traverse all subdirectories in and do something in Unix shell script

I am new to bash scripting. I am working on a shell script and got stuck from last 3 days. I want my shell script to visit all subdirectories in a main directory. Do something in directories, sent ...
1
vote
1answer
32 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
1answer
749 views

Running shell script inside with vagrant provision

I have setup a vagrant box using precise64 (ubuntu 14.04) and installed packages needed for octopress. I can ssh into the vagrant box and generate posts and run preview for my octopress site. Now I ...
8
votes
3answers
10k views

getopt, getopts or manual parsing - what to use when I want to support both short and long options?

Currently I'm writing a Bash script which has the following requirements: it should run on a wide variety of Unix/Linux platforms it should support both short and (GNU) long options I know that ...
1
vote
2answers
36 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
0answers
36 views

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

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
2answers
114 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 ...
2
votes
1answer
45 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 ...
1
vote
2answers
69 views

Ping a host, check if alive or not, and send result to file via a shell script

To clean out my custom hosts file and remove dead domains on Windows I ping the hosts from domains.txt, and if I get a reply I add that host to result.txt: @echo off >result.txt ( for /f %%i ...
3
votes
2answers
92 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 ...
15
votes
2answers
5k views

Are there naming conventions for variables in shell scripts?

Most languages have naming conventions for variables, the most common style I see in shell scripts is MY_VARIABLE=foo. Is this the convention or is it only for global variables? What about variables ...
2
votes
3answers
119 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' ...