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

learn more… | top users | synonyms (2)

0
votes
2answers
42 views

Combining two scripts into one

I have two scripts. Both scripts are on the same server (serverA) The first one (serverA) makes an ssh connection to the other server (serverB), and executes the second script, e.g *script1* ssh ...
8
votes
3answers
425 views

Extract text between three single quotes

I have the following in a file description: ''' This rule forbids throwing string literals or interpolations. While JavaScript (and CoffeeScript by extension) allow any expression to ...
0
votes
2answers
24 views

return value of command not displayed in script

If I execute the below rsync command in command-line , I am getting the proper return status /usr/bin/rsync -azv -p /home/zaman x11server:/home/zamanr &> rsyncjob/output."$datetime" echo $? ...
0
votes
3answers
41 views

How to put variable in for loops? [duplicate]

for seq in {046725..046899} do #body done Above segment of code runs beautifully keeping preceding zeroes in seq variable but why following code segment doesn't run? Is there any way? I need seq ...
-2
votes
2answers
109 views

shell scripting if statement doesn't work [closed]

I wrote that script but if I run it I get this output: ./autotex: line 7: syntax error near unexpected token `then' ./autotex: line 7: ` then' The script is: #!/bin/bash while [ $key = ...
43
votes
4answers
910 views

How does bash differentiate between brace expansion and command grouping?

I've noticed that { can be used in brace expansion: echo {1..8} or in command grouping: {ls;echo hi} How does bash know the difference?
0
votes
2answers
29 views

Bash script doesn't convert variables [duplicate]

I was attempting to create a bash script to run a backup of my Raspberry Pi to my Box account via FTP. Most of it works, but for some reason it won't convert variables to the text they stand for. When ...
1
vote
2answers
37 views

How i check if a specific number.word exist in a line?

like i have this lines on the file {218394 ted 'y' ted} {131241 john 'n' ted} and i want to check if its y continue if its n dont ! i have this code until now!: read -p "Enter your answer : " echo ...
1
vote
1answer
44 views

How to get a deterministic complete dump of all iptables rules?

How to get a deterministic complete dump of all iptables rules? By complete, I mean all tables of iptables. By deterministic, I mean when the command is run multiple times without modifying any ...
3
votes
3answers
42 views

How to treat numbers starting with zeroes as decimal integer

Input would be file name like following : A-B-000001-C A-B-000002-C ..... ..... A-B-999999-C All file should be sequential. I want to find missing sequential file names. For this I'm separating 6 ...
5
votes
2answers
68 views

In bash script, what's the different between declare and a normal variable?

In bash scripting: we create variable just name it: abc=ok or we can use declare declare abc=ok what's the different ? and why bash make so many ways to create variable?
1
vote
1answer
43 views

one-dimensional array in shell not working for indexes greater than 08

I have been wondering why the one-dimensional array in shell isn't working for the sub-script / index 08 and 09. How come this happen? $ cat check month_arr=(0 31 30 31 30 31 30 31 31 30 31 30 31) ...
-1
votes
0answers
23 views

How can i list a specific line/word from my text?(shellscript)

I have this until now: if [[ $1 = "-s" ]] && [[ $2 =~ ^[0-9]+$ ]] echo "ok" for $2 = 1 awk {print $1} something.txt fi what i want is when for example when i enter -s 2 to list the second ...
2
votes
3answers
172 views

Can I put ranges to parameters? [duplicate]

I have this code: if [[ $1 = "-s" ]] && [[ $2 = 0-9 ]] then echo "yes" fi 0-9 does not work for me. What I really want is to type, for example, -x 3 (or any number).
0
votes
2answers
67 views

Making csv file

I have two different textfiles.txt (textfile1.txt and textfile2.txt) with different data sets in them. Is it possible to compile two seperate .txt files as a single CSV file? UPDATE textfile1.txt ...
2
votes
1answer
28 views

Appending to a file suffix range with echo and tee

I am unable to figure out how to properly pipe and tee to append to a range of files. Instead of manually typing them out echo "help!" | tee >> file1 file2 file3 I am trying to figure out: ...
3
votes
1answer
47 views

Colored Output from Bash Script

I'm running grep inside a bash script. If I run the grep command directly, I see colored output of the file name and search string: grep -i username /tmp/sess_* If I put that command in a bash ...
1
vote
5answers
57 views

Filtering out inputs to textfile

I am using and Raspberry Pi (running raspbian) and I have a shellscript continuously outputting values into textfile via this command: wavemon -d |grep -i signal >> textfile.txt The output is ...
0
votes
1answer
74 views

How do I ask password by GUI prompt while using sudo in script?

I use Trisquel GNU/Linux with GNOME Flashback Desktop Environment. I need a GUI password prompt for user for executing command with sudo in script. Example consider following script: zenity ...
0
votes
1answer
70 views

How to prompt a password automatically in Unix Shell script? [duplicate]

I have the below line in a script. When I run it, it prompts for a password to copy files in the server. I need the password to be taken from the script. Please help me resolve this. for i in cat ...
0
votes
1answer
52 views

Unable to kill a process in shell script

I have this script: #!/bin/sh cd ~/.devilspie && devilspie Minimize.ds pkill devilspie exit 0 The first command runs absolutely fine, but in the second line where it needs to kill the ...
0
votes
1answer
19 views

For loop separate $i's [closed]

Hi I want to have "NOTHING HERE" to come out of the for loop but I get NOTHING and HERE pi@ed_pi:~ $ cat test.txt NOTHING HERE pi@ed_pi:~ $ for i in `cat test.txt`; do echo $i; done ...
1
vote
2answers
38 views

Script to Organize Desktop into Folders/Directories by Extension

I'd like to organize desktops by running a script that places all of your files into folders by extension. I found some code through googling and the code I found creates a folder with the name of the ...
0
votes
2answers
37 views

script not reporting service status correctly

I have a script that I use for iperf to be able to start, stop, and check the status of it like a typical service. If I issue a "service iperf start" or a "service iperf stop" it works correctly. When ...
-4
votes
1answer
34 views

find problems again? [closed]

How do i show pipe or socked files from a directory? echo "give name of directory: " read directory if [ -d "$directory" ] then echo "thanks again" else exit fi find $directory -maxdepth 1 -type ...
-1
votes
0answers
15 views

find command problem [duplicate]

I want to show the subdirectories of the given directory that have been accessed by the 'x' last days when x a argument of mine! echo "give name of directory: " read directory if [ -d "$directory" ...
-1
votes
0answers
29 views

find(shell script problem )

I want to show if the files of the given directory changed contents during a specific time period and I want to be able to set that time period as an argument. echo "give name of directory: " read ...
0
votes
3answers
70 views

`Syntax error: “(” unexpected` when creating an array

I have two (Debian) Linux servers. I am creating a shell script. On the first one I create an array thus: #!/bin/bash target_array=( "/home/user/direct/filename -p123 -r" ) That works fine. ...
0
votes
2answers
29 views

Shell script - blanks are not always recognized as such?

I'm confused on how bash interprets blanks while executing a script. In the end, I want a script that is fed by a csv file containing software used by an organisation and it should return the CVEs for ...
0
votes
3answers
21 views

problem with find (shell script)

I want the files of a given directory and use the following script: echo "give name of directory: " read directory if [ -d "$directory" ] then echo "thanks again" else exit fi find /-type f ...
1
vote
2answers
37 views

cd in bash script without alias, function, source [duplicate]

I have a little problem, and hope that anyone can help me. I've written a bash script which should cd me to a directory. My problem is that only the directory in the subshell changes. I've read of ...
0
votes
0answers
26 views

Track command line with timestamps

I want to create a program that audits the command line I/O of a terminal session using its PID. I found out about script command which is pretty much the same to what I want, but the problem is that ...
0
votes
1answer
24 views

Execute a init script from C++ program

I have a script in my /etc/init.d/ which executes an application. I am able to start,stop and get status of the service from terminal. Now I would like to start the same service from my C++ program. ...
3
votes
2answers
82 views

ifdef style conditional inclusions for shell

Consider the following script. #!/bin/sh echo "" | ...
3
votes
1answer
39 views

how to remove 0 (zero) from the day and month but not from the year (01/09/2012) using in Linux (Redhat)

Using Linux (Redhat) I need some help regarding the a/m request When I use dialog: --calendar to output the date. The format will be dd/mm/yyyy but I need the format to be d/m/yyyy for day and month ...
-2
votes
2answers
82 views

How do you remove newline character in the middle of file?

File structure: Col1|Col2|Col3|Col4 123|456|abcdefg Tel.: 689346589934, xyz lckhasfkl|abc I want to remove the newline character from 'col3' only.Please suggest
3
votes
3answers
69 views

while read line in shell script - how to stop the loop?

I read a tutorial here that I can use while read line do wget -x "http://someurl.com/${line}.pdf" -o ${line}.pdf done < inputfile However this script keeps running with $line not containing ...
1
vote
3answers
76 views

Add line to configuration file from a bash script?

I am trying to figure out to locate a line in a configuration file, then to drop down two lines then to insert a line of code. I was attempting to do this in awk/sed but got stuck on the carriage ...
1
vote
2answers
56 views

How to use single quotes inside ssh and sqlplus

Below script helps me to ssh and do sqlplus to fetch info from database. I checked and it worked well but the only problem is if i use single quotes in the sql query then I am getting an error since I ...
0
votes
0answers
34 views

Fetch data from a CSV file based on multiple conditions

I'm trying a write a generic shell script which should extract data from a CSV file based on multiple conditions (generic) and write it to another CSV file. Sample CSV file: ...
8
votes
4answers
181 views

dirname and basename vs parameter expansion

Is there any objective reason to prefer one form to the other? Performance, reliability, portability? filename=/some/long/path/to/a_file parentdir_v1="${filename%/*}" parentdir_v2="$(dirname ...
13
votes
1answer
345 views

Where are bash line continuations after && and || documented?

I have seen this construct in scripts a lot and used it myself, but it bothers me that I can't seem to find it in the documentation. Example: [ -f file1 ] && [ -f file2 ] && echo ...
0
votes
0answers
32 views

Startup Profile Not Running From Bash Script, Only Manually

I'm creating a bash script to deploy CA ITCM (for Mac OSX) and upon completion of the install there is a command that can be ran to start all the services so that a reboot is not required. The command ...
3
votes
1answer
30 views

How to detect the architecture of the chroot from inside the chroot?

Let's say for example the host system is running Debian amd64. And on that system, another Debian i386 has been installed inside a folder using debootstrap. Then assume a shell script is running ...
1
vote
3answers
53 views

Find Directory if Number of files is over X

Am wondering if someone can advise on the best way to do this. In my Web Dir is around 100 folders; each folder is a clientID. Within each ClientID folder is a Sub-Set of folders. In each subset ...
2
votes
1answer
38 views

Inline debug (xtrace) in scripts

Is there a way to force enable or disable debug (xtrace) per command line in scripts ? In Windows Shell ("ms-dos") is an "@" which can prefix a command line, disabling that line to be showed if the ...
1
vote
1answer
29 views

How to have netcat server close after n seconds

I need to use nc in a weird way, where I want the server to first send a file, and then recieve a file, and this repeats. I would like to have every instance of the server server close after some ...
0
votes
3answers
78 views

How to display size “human-readable” in lsof | grep /var* [duplicate]

I am currently trying to see , all the files which are using /var mount. With lsof | grep /var* when Its displaying size in bytes. How can I display file size in MB. Thank you.
2
votes
2answers
53 views

SOLVED: Shell Script cant run man command

I have a script that runs commands & takes a screen shot. I want the man file to display & grab a screen shot of it. My script works for the commands alone but if I add "man " before the ...
0
votes
0answers
28 views

Tmux displays “<xzy not ready>” in the status bar

I'm using iTerm 2 nightly and I have the following tmux config setting for the left status bar: set -g status-left "#[fg=green]#h @ #[fg=cyan]#(extip | awk '{print \"ip \" $1}') ...