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

learn more… | top users | synonyms (1)

0
votes
1answer
97 views

shell script - echo command not printing in proper sequence

I have the following testfile.txt: string1 1 string2 2 string3 3 string1 2 string2 4 string3 6 string1 3 string2 6 string3 9 I have the following script: #!bin/sh ...
0
votes
0answers
34 views

Bash script to identify which init system the system currently using [duplicate]

I have to create a script that will mount my /usr folder as aufs. I compressed it using squashfs. I've managed to install a working systemd init in ubuntu which I am currently using. Because the ...
0
votes
1answer
67 views

shell script - reading from standard input versus a file

I have the following input file in.txt: a b c a b c I have the following script test.sh: # display unique rows while read line do echo $line done < $(cat "$@" | sort | uniq) # display all ...
2
votes
0answers
79 views

Number comparisons in BusyBox ash

I have the following script that extracts data from the EXIF command on my BusyBox ash-based system. I parse the date tag from the end of the file and use case as a final check to ensure the format ...
1
vote
2answers
63 views

Cygwin - Shell Scripting (eval and echo)

I have the following file f1.txt: A=0 A=\`expr $A + 1\` and the following script file s1.sh for line in $(cat testfile.txt) do echo "$line" # eval $line done echo $A When I run the ...
3
votes
1answer
84 views

Can someone clarify this Bash script

I'm learning something about Bash scripting, and I came across this example: The task is to write a Bash script that reads a file, given with the first argument, pulls out those records that have the ...
1
vote
1answer
59 views

removing data from txt file

I have a comma-delimited giant file that was exported from a database. The file has this format Date,n1,n2,n3,n4,n5,n6,color,type,reference 10-Jan-2000,344,13,21,2,55,3,"rose garden" ,3444,32 ...
2
votes
3answers
42 views

To assign variable from a file separated by delimiter

I have a text file with datas as below separated by delimiter: 1000:Tom:user1 1002:Jerry:user2 1003:Victor:user3 1004:Jason:user4 I need to run a while loop (any loop) to fetch details from first ...
4
votes
3answers
178 views

Help Shell script to pass variables to rsync

I'm trying to create a simple wrapper shell script for rsync. When I send file names to my script, rsync can never seem to identify the correct location. The file names have spaces in them. I've tried ...
0
votes
2answers
137 views

Shell scripting: -z and -n options with if

I have a shell script where we have following lines if [ -z "$xyz" ] and if [ -n "$abc" ], but I am not sure what their purpose is. Can anyone please explain?
2
votes
1answer
266 views

“stdin: is not a tty” mails for running scripts as cron jobs

I have several shell scripts (bash) which are started by cron. Every time a script is executed I get an email saying "stdin: is not a tty". Can someone please tell me how to fix this? All scripts run ...
5
votes
1answer
96 views

How to append multiple lines to a file without last newline?

I have a very long string that is split in chunks. I want to append them to a file without putting the newline character using bash. Example: First append cat >> abc.sh << EOL echo "bla ...
4
votes
1answer
65 views

What's the difference between sh script and sh < script

What's the difference between sh myscript and sh < myscript I played around and they seem to have the same effect. Are they equivalent?
3
votes
2answers
86 views

Expansion of a shell variable and effect of glob and split on it

This post actually contains two separate questions but I think grouping them together will give some more context. I have gone through this question on quotes around variables but I do not quite ...
2
votes
1answer
60 views

Bash:source files without fullpath?

if I source the script file without pre-path definition, it does not work. What is happening below? I have got a go1 function in the file simply printing $PWD. $ bash --version GNU bash, version ...
1
vote
1answer
30 views

Problematic quotations

#!/bin/ksh typeset FILE_SIZE1=$(stat -f '%z' test.txt); typeset -r BK_STATARGS="-f '%z'" typeset FILE_SIZE2=$(stat ${BK_STATARGS} test.txt); echo without arg var ${FILE_SIZE1} echo with arg var... ...
1
vote
2answers
75 views

Script to su -c into a screen is not working as intended

I'm working on a script that will allow me to load up a screen from a user via sudo and su -c. However, when I use it, it will just show the shell of the user: sudo su -c "script /dev/null; screen -r ...
2
votes
2answers
47 views

Help with 64-bit integers in scripts?

Maybe I'm overthinking this (although I don't think I am)....or maybe there's a neater way of solving my problem ? I have a requirement that if a file is larger than 1GB, it gets split into smaller ...
0
votes
0answers
20 views

Multiply 2 array index variables shell programming [duplicate]

How do i multiply 2 array index variables given the following foo=(1 2) bar=(0.1 0.2) foobar=$((foo[1]*price[1])) # this is wrong echo "$foobar" Current output : 0 Correct/Expected output : 0.4
1
vote
1answer
49 views

How to FILTER the files with filename and then DELETE the OLDEST file from there? [duplicate]

I create and keep the following automated backup files e.g.: fruits_29-12-2013.gz fruits_30-12-2013.gz fruits_31-12-2013.gz sweets_01-12-2013.gz sweets_02-12-2013.gz sweets_03-12-2013.gz .. ...
3
votes
1answer
104 views

Compare users out of an array with /etc/shadow file

I want to check for all users who do not have a password set. For example, a user with the following entry in /etc/passwd test01::15164: ...* has no password set. I would like to list all such ...
2
votes
2answers
80 views

Show a sliding window of output from a program

I want to run a command (rsync -av) and only display 10 lines of output at any time. I have found a similar post, but I don't want to redirect it to a file. I want the output to be displayed ...
3
votes
1answer
90 views

USB device to be detected at the “same” /dev point always?

In Linux (actually I'm with CentOS v6.5), whenever I plug in my USB Terminal/Character Device (some kind of USB Adapter) for the first time (after booted), it is detected at: /dev/ttyUSB0 But ...
4
votes
2answers
477 views

How can I trigger an event in shell script when an USB device is removed?

I need to do some actions when a specific USB device is removed/added. I need a fast response on the order of milli-seconds. How can I do this in a shell script?
3
votes
1answer
52 views

Common flag designations and standards for shell scripts and functions

I have been adjusting to using GETOPT and GETOPTS in my shell scripts and custom functions to enable me to use the functions that I create more flexibly. After using a number of UNIX functions I have ...
3
votes
3answers
82 views

Code duplication in a shell script

My bash script (lets call it myscript) takes input either from stdin (pipe), or form a regular file (if filename was provided as an argument) a) someprog | myscript or b) myscript file.txt ...
3
votes
2answers
109 views

How to output to screen overriding redirection

Is it possible, within a shell script, to write to the screen while STDOUT and STDERR is being redirected? I have a shell script that I want to capture STDOUT and STDERR. The script will run for ...
0
votes
5answers
166 views

On executable files in Linux [closed]

It is said that in linux, unlike Windows, there's not a clear border between executables and other files. Well, in Windows, I write a C++ program, then it is precompiled, compiled and then linked to ...
5
votes
5answers
602 views

How to parse ISO8601 dates with linux date command

I'm trying to use the date command to generate a file timestamp that the date command itself can interpret. However, the date command does not seem to like its own output, and I am not sure how to ...
0
votes
1answer
54 views

Curl command help

I'm trying to connect to a internal tool UI, then login and later logout. The homepage is having 3 drop-down options and 2 tabs where we need to enter the IP & Port and then connect. Once ...
0
votes
2answers
62 views

Merging two different files with conditions

I have two different files as shown below. Content of a.txt: HDR|1|||||||||| DTL|@||||||||||| TLR||||||||||||| HDR|1|||||||||||| ...
1
vote
2answers
55 views

Mailing out a customised content based on specific search in a logfile

Using below test.sh, I am getting result in dump.txt as below: test.sh: #!/bin/bash #"Maxl-script" zone starts..... essmsh -l admin password -s localhost -i << EOF spool on to 'dump.txt'; ...
0
votes
2answers
72 views

How to Lookup the values of an index values from a big data file?

I have a data file (data_array.txt in the example) and index file, index.txt, at which I want to extract the data from the data file that have the same ID in the index file and store in to a new file, ...
1
vote
5answers
253 views

Cut and transpose some lines of a file

I have 1344 rows of data column. I want to form 32 row by 42 columns from my input data file. I want to cut the first 42 row and paste to one raw of 42 column data and continue down likewise. My data ...
3
votes
5answers
259 views

What are the special characters to print from a script to move the cursor?

I found that by printing \r from a script the cursor moves to the beginning of the line. What character will move the cursor up one line? Where is a list of these special characters? EDIT: Working ...
3
votes
1answer
112 views

CPU is free, yet bash script not utilizing all CPU resources

I ran a simple script to generate a large (10000000 lines) csv file with 6 fields in which some fields changed in each line/row, using a while loop. The machine had all (32) CPUs free, lot of RAM (~31 ...
2
votes
1answer
302 views

How to check the status of bash shell script while executing from Python script?

I have a simple Python script which will execute a shell script using subprocess module in Python. Below is my Python shell script which is calling testing.sh shell script and it works fine. import ...
3
votes
1answer
79 views

When I try to add the Android SDK to my PATH, it gives a context error

I'm getting a weird message when my shell reads .profile: /Users/alex/.profile:export:69: not valid in this context: SDK/tools:/Applications/Android The error is triggered by this line in my ...
-1
votes
2answers
165 views

Count the number of characters in all files [closed]

A file foo contains a list of filenames. Devise a single statement that stores in a variable count the total character count of the contents of these files.
0
votes
1answer
53 views

How to write a script that will open up multiple tabs in the terminal?

I am on OSX and using iTerm I have this so far #!/bin/sh open /Applications/iTerm.app & exit 0 So after opening, I need two windows and one of those windows will need to open 6 tabs. two of ...
1
vote
2answers
44 views

Shell script not working to open LimeChat through the terminal

I created a shell script that I will execute in the morning to open up all the apps that I want startup.sh #!/bin/sh open /Applications/Firefox.app & open /Applications/Messages.app & open ...
2
votes
2answers
210 views

Obtain exclusive read/write lock on a file for atomic updates

I want to have a file that is used as a counter. User A will write and increment this number, while User B requests to read the file. Is it possible that User A can lock this file so no one can read ...
0
votes
1answer
50 views

if env variable exists then exit out of script

#!/bin/bash if [[ -n "$MYVAR" ]]; then exit; fi # otherwise the rest of the script continues... I'm trying to exit out of a shell script if a certain ENV variable is 0. The script above does not ...
2
votes
2answers
241 views

How can I print only certain commands from a bash script as they are run?

I have a bash script with various if statements based on command line arguments I pass in when calling it. Having some kind of output as to what commands are being run is helpful to confirm the flow ...
0
votes
3answers
54 views

apply specific command for each git repository

I want compress all the git repositories on my computer (say in ~). I.e., for each directory {}, that contains directory or file (in case of submodules) named .git, I want to execute git gc ...
0
votes
4answers
106 views

How to check the process along with its arguments in process list?

I have written a script where i need to pass several arguments with the same script, the script is being executed after a certain time using cron. In order to make sure that there are no multiple ...
2
votes
2answers
42 views

Generate man page in realtime?

I'm working on a command line scripting framework. We would like to generate man pages for our commands. However they are quite dynamic depending on your installation. So ideally we could intercept ...
3
votes
3answers
60 views

capture output from command without interference

How can I test whether a command's output is an empty string without interfering with said output? Example: command | ??? if [ $? = 0 ] && [ -n "$output_from_command"]; then ... I'd ...
-3
votes
1answer
60 views

where is this HOME environment variable and what do I have to add -H too it?

I recently attempted to run a boot up script which failed I didn't know why it failed so I posted a question about that here. chkconfig bootup script failing, script runs good manually Where the ...
1
vote
1answer
52 views

compiling nginx shell fails from salt provisioner

I have a salt provisioner that is calling a shell script to compile Nginx with a few modules that are needed. This is the call to the script in the .sls: nginx: # pkg.installed: # - name: nginx ...