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

learn more… | top users | synonyms (2)

1
vote
1answer
37 views

dialog menu to display files and select one of them

I want to display all the files under /home directory in menu, and select only one of them. Then the script will print the full path of the selected file. I have created the following script. This ...
4
votes
1answer
234 views

Bash: Variable assignment doesn't seem to 'stick' [duplicate]

I am having a hard time tracking down the reason my 'boolean' flag variable won't stay false when a test fails inside a while loop. The script involves a few loops but essentially it is intended to ...
1
vote
1answer
33 views

maintaining the same filename

I already have a working command to copy a file between different virtual machines. But I want the copied file to automatically have the same filename as the original file. So I want to create a ...
-1
votes
1answer
28 views

shell script - Unable to execute Java with parameters

I have written a shell script that will take a parameter, pass that parameter to Java command. But I get error during the execution. Here is the script: #The script takes an input, the file name to ...
-1
votes
3answers
41 views

Delete oldest files from a directory if number exceeds seven

Daily downloads are stored in a directory. A script has been created which counts how many files reside in this folder. The part I am struggling with is deleting the oldest file in the directory if ...
0
votes
1answer
28 views

A set of libraries like ncurses in a shell script

Supose you present the following TUI in the shell: I need a set of libraries that can be used in the shell to do it. Being sure, ncurses has not been used, because it make a dependecy. Question: ...
1
vote
1answer
40 views

Use case for /usr/bin/lessecho

I can not come up with an example of how I could/would use lessecho. The description in the man page is fairly straight forward but is not helping me come up with a use case: DESCRIPTION ...
2
votes
2answers
44 views

Pass two (piped) shell commands as a parameter to a shell function

I have defined the following shell functions: success() { printf "[\033[32mSUCCESS\033[0m]\n" } failure() { printf "[\033[31mFAILURE\033[0m]\n" } try() { result=$($* 2>&1) if [ $? ...
5
votes
4answers
186 views

How can I cat the contents of files found using find into a single file?

I managed to shoot myself where it hurts (really bad) by reformatting a partition that held valuable data. Of course it was not intentional, but it happened. However, I managed to use testdisk and ...
2
votes
2answers
54 views

Fetching individual bytes from a binary file into a variable with bash

I need to make a fairly simple bash script to pull bytes one at a time from a binary file, send it out a serial port, and then wait for a byte to come back before I send the next one. This is ...
2
votes
1answer
50 views

AIX question on cp command [closed]

I have come across an issue with cp command. We are using ksh and cp command goes like below cp -p $PATH/file_name_${VARIABLE}_???.dat $PATH/file_name_to.dat ??? - is for any three digit numbers. ...
5
votes
1answer
310 views

Determine if Git working directory is clean from a script

I have a script which runs rsync with a Git working directory as destination. I want the script to have different behavior depending on if the working directory is clean (no changes to commit), or ...
0
votes
1answer
32 views

shell script to download info. about movies from imdb/thmb and putting it into an .nfo file for per-use

Does anybody know of a tool which will extract info. from imdb.com/themoviedb.corg and dumping it into a text file ? I have been searching but with no luck . I usually get the movie name but want to ...
0
votes
2answers
34 views

Remove by date in Shell Script

I have a shell script that creates a backup of a database. I would like to keep the last 7 days for files. What is the syntax I need to remove files in a directory by date or can I keep the newest 7 ...
3
votes
4answers
133 views

Test if command accepts a specific option

What is the preferred way to test if a command takes an option? What are the caveats? As a motivating example, at login my shell aliases grep to add several --exclude-dir options but this option is ...
2
votes
2answers
33 views

Change path in sql script with sed

I'm trying to change the path in a oracle sql script from a bash script. read -e -p "Enter the ORACLE SID: " -i "orcl" ORACLE_SID_VALUE sed -i "DEFINE tsdir = '/u02/app/oracle/oradata/orcl';/c\DEFINE ...
0
votes
4answers
38 views

sftp script to get a file from remote machine

I use a script, which contains the line: sftp $FTP_USER@phcsftp.pearsoned.com:/dir/file.txt When I run the script, it asks for my password: user@phcsftp.pearsoned.com's password: However, ...
2
votes
3answers
50 views

Repeat Last N commands [duplicate]

In bash, I tried writing a script to run the last N commands. For say, N=5 for i in {1...5} do !-5 done The problem is that !-5 gets replaced by the 5th-last command on my shell (say time) and ...
2
votes
1answer
16 views

batch tool for sending files over webdav

I know there is cadaver for working with webdav. But it opens an interactive console. I want to write a script that will send files over webdav protocol in a batch mode. What tool can I use?
4
votes
2answers
62 views

Shell script error handling while assigning STDOUT to variable

I am trying to implement error handling in my shell script as described in the 2nd answer in Best practice to use $? in bash? My script looks like this: #!/bin/bash try() { "$@" code=$? ...
1
vote
0answers
31 views

Verbose output in logfile and simple output on screen?

Let's say I have the following script: script.sh and i want the verbose output in a logfile and simple output on screen. Logfile should contain the csh -v script.sh output, and on the screen should ...
2
votes
1answer
45 views

How can I pipe the output of a program or function into a variable?

How can I pipe the output of a program or function into a variable? For example lets say I have this script: function foobarize () { sed \ -e "s|${foo}|${bar}|g" \ $1 } echo foo | ...
4
votes
3answers
107 views

How do I capture stdin to a variable without stripping any trailing newlines?

In a shell script... How do I capture stdin to a variable without stripping any trailing newlines? Right now I have tried: var=`cat` var=`tee` var=$(tee) In all cases $var will not have the ...
3
votes
2answers
52 views

Go up one level from a nonexistent path

I have some code like this in a script (bash) file: if [ ! -d $dir ]; then cd $dir/.. git clone http://... fi Of course as written this doesn't work since $dir does not exist. Is there a ...
2
votes
1answer
22 views

scp (v4) copy from remote to multiple local filenames

I did a bunch of googling and I think what I am trying to do is not possible with openssh/scp v4.x but wanted to ask here in case someone has a creative workaround. I want to copy multiple files from ...
2
votes
1answer
32 views

Installing noip via sh script

I have this script: cd /usr/local/src/ wget http://www.no-ip.com/client/linux/noip-duc-linux.tar.gz tar xf noip-duc-linux.tar.gz cd noip-2.1.9-1/ make install <<END_SCRIPT Username password ...
1
vote
3answers
252 views

“Can't cd to /home/user” when sourcing a script

I have this script: echo $HOME cd $HOME cd / cd /usr/local/src/ When I run it like this . script.sh I get this output: /home/user : No such file or directory : No such file or directory : No ...
1
vote
4answers
55 views

How to have service that makes sure program keeps running?

I made a service called thin_keep_alive_service in /etc/init.d. I gave it chmod +x rights. The script looks as follows: #!/bin/bash ### BEGIN INIT INFO # Provides: thin_keep_alive_service # ...
3
votes
2answers
101 views

get result text from CLI command

I'm writing a bash script and I need to capture the text resulting from the output of the rsync command, for instance, the following command: rsync -av "$FOLDER1" "$FOLDER2" prints: ... sent ...
12
votes
2answers
433 views

When running a shell script, is it possible to pass specific positional parameters without having to enter them all in order?

For example, if I have script ./foo that takes 10 parameters, and I only want to pass the 8th parameter. The only way I know how to do this currently is: ./foo '' '' '' '' '' '' '' 'bar' Is there ...
1
vote
2answers
62 views

grep works fine in command line but returns nothing in script

I'm trying to write a small script to get me list of files that match certain criteria into a file. #!/bin/sh cd /var/www_data/patch/ grep --include=\*.{php,ini,conf,sh} -ril -P ...
1
vote
0answers
25 views

script started in .xinitrc stays in processes

I have made a little startup bash-script to run before my wm starts. Unfortunately after X and WM is started this script is still listed in the in htop and I don't have a clue why... this is the ...
0
votes
0answers
38 views

Script to compare directories and move files (like rsync)

I use rsync to sync data between two servers. If I completely rebuild the directory structure, rsync cannot understand this and will attempt to recopy everything. I am aware that Unison is capable ...
1
vote
2answers
41 views

Pass parameter from one shell script to another

I have two shell scripts namely test1.sh and test2.sh I have to call test2.sh from test1.sh For test1.sh I need to pass one parameter as a command line argument and for test2.sh I need to pass a ...
1
vote
1answer
53 views

make `find` return with a non-zero exit code if error occured

Why am I seeing the following: $ find -not -exec bash -c 'foo' \; -quit bash: foo: command not found $ echo $? 0 This is a reduced version of the actual script I am using which I post at the end ...
5
votes
2answers
45 views

bash crashed with for loop [duplicate]

The question may be trivial but with this simple for loop for i in {1..10000000}; do echo "$i" line >> file done my shell crashed after some elaboration time (the tab in the terminal emulator ...
4
votes
1answer
76 views

How to catch a signal in command line?

I asked this question. SIGPIPE signal is generated to stop the execution of the command as told in the answer. But how do I capture this signal and gracefully terminate the command? The command exits ...
2
votes
1answer
96 views

Test if telnet port is active within a shell script

I am trying to create a script to test whether it is possible to login via telnet. I do not want to really log in; therefore, expect is not needed. I just want to see if I am able to get a login ...
1
vote
2answers
42 views

Error: ambiguous redirect while transferring output to command

Output to redirect in script: 511@ubuntu:~/Unix/test$ ls -ltr |awk '{print $9}' default.txt dfah.txt fruit.txt fruit_prices.txt dfh.txt header.txt testfile.txt topoutput.txt Script written on shell ...
4
votes
4answers
141 views

extract lines according to a particular column

I have a CSV file like CK,ck XYZ,xyz,xyzs ABC,abc,abcs PQR,pqr,pqrs LMN,lmn, IJK,ijk, I have to check if something is written in column 3 except whitespace, then display the whole line.the output ...
2
votes
3answers
57 views

When was the script started?

What I want is, -bash-3.2$ ps -aef | grep 29137 jeeadm 9794 1190 0 09:22 pts/2 00:00:00 grep 29137 jeeadm 29137 1 0 Sep02 ? 00:00:21 Java Second Row, Fifth Column entry, as in ...
3
votes
3answers
90 views

Determine maximum column length for every column in csv-file

To determine the maximum length of each column in a comma-separated csv-file I hacked together a bash-script. When I ran it on a linux system it produced the correct output, but I need it to run on OS ...
0
votes
3answers
40 views

Stat usage in truss command?

I want to get the access time and modification time of the file in unix solaris machine. The `stats command was not found in that solaris machine. Could you please suggest which is the alternative ...
-1
votes
1answer
26 views

How to do calculation on eval variables in shell script

I want to do mathematical operations on eval variables in shell script, but it is not working. query=first eval avgOverall$query[1]=28.5 avgOverall=$(("`eval echo '${avgOverall'$query'[1]}'`+1")) | ...
1
vote
0answers
27 views

Running multiples query on Hbase shell without calling hbase shell again [migrated]

To invoke shell again takes time , i want to execute multiple commands by invoking hbase shell once.Below code run only single query. cmd="echo \"put 'test', 'row1', 'cf:a', 'value1'\"| hbase shell" ...
3
votes
1answer
63 views

Save lines to different files based on the date

How can I force a re-evaluation of this each time? cat > $(date '+%H-%M-%S').log So that when I first output something it gets written to one file, and after a few seconds I make another ouput ...
1
vote
3answers
71 views

rename files with rename command

Please advice what is wrong with the following command find /tmp/dir -name "* *" -type f | rename 's/*/fixed_/g' remark - I prefer to do that with one command not loop syntax What I want is to ...
1
vote
1answer
70 views

Adding Text After Specific Line of File in Bash Script

I have a txt (ip.txt) file that contains IP addresess. I group them under TCP and UDP. File excerpt is below: #TCP 162.298.38.930 162.298.38.931 162.298.38.932 #UDP 162.298.38.930 162.298.38.931 ...
1
vote
1answer
52 views

Why is the output of this paste command split on separate lines with indents?

I was trying to merge files using either of these commands: paste data_{1..2}.txt > 1_2.txt paste <(awk '{print $1}' data_2.txt ) <(awk '{print $1}' data_2.txt) > 1_2.txt But the ...
1
vote
2answers
39 views

Using sed with herestring (<<<) and read -a

I use sed with <<< and read to assign all words in a string to variables. What I do is: read -a A0 <<< $(sed '2q;d' /proc/stat) Hence, sed reads the second line of the file file ...