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

learn more… | top users | synonyms (2)

2
votes
1answer
41 views

Unexpected result when using command line arguments to look for file with symbol

I'm trying to write a script that accepts 2 command line arguments e.g. one a directory name the other a symbol (any symbol can be $,£,^,* and so on). It should then check if the directory has a file ...
2
votes
2answers
35 views

Unzip into directory, independent if directory is contained in ZIP

Let's assume I've a ZIP file whichs content may look like # file: with_out_dir.zip file1.txt file2.cpp file3.js some_sub_dir/ - file_in_subdir.txt file4.xml but it may also look like this # file: ...
1
vote
2answers
48 views

assign output of a c program to a shell variable: token error

I have a shell script to run several times a .c program ('switch') which admit 3 input paramenters. I want to run the program 4 times passing values {4,16,32,64}, and for parameters ...
3
votes
3answers
316 views

Better way to run single for loop instead of two for loops

This works but the way I did this is kind of silly. Is there a better way to do this? for e in $(ipcs | awk '{print $2}'); do [[ "$e" = "Semaphore" ]] && break echo $e ipcrm shm ...
-1
votes
1answer
44 views

syntax error: unexpected end of the file

#!/bin/bash #organization: Seneca College #Purpose: Validate a date #Usage: chkdate year month day # year=$1; month=$2; day=$3; extra=$4 if [[ "$year" == "" || "$month" == "" || "$day" == "" ]]; then ...
2
votes
1answer
52 views

can't execute a command even i'm in the group and command is -rwx--x---

I'm in $ORACLE_HOME/OPatch directory and when I type opatch then I get the response as, -bash: opatch: command not found If I do ./opatch, then I get the response as, /bin/sh: ./opatch: ...
-1
votes
1answer
39 views

how to select multiple exit

I'm new to bash scripting and I don't understand what's wrong with this specific part of my script. im trying to select all the exit that have in my script. and trying to put in conditon that if all ...
1
vote
1answer
55 views

shell for loop with find with filenames containing spaces [duplicate]

Consider a directory with typical Microsoft Windows filenames: New Document.txt Foo.doc Foo - Copy.doc I'd like to do something on each file such as: for sendfile in $(find ${POLLDIR} -type f ...
0
votes
2answers
44 views

Bash Mysql Command Substitution Login Failure

Bash and MySQL versions: GNU bash, version 4.2.25(1)-release (x86_64-pc-linux-gnu) mysql Ver 14.14 Distrib 5.5.37, for debian-linux-gnu (x86_64) using readline 6.2 I have a bash script that tries ...
2
votes
2answers
82 views

Bash not equal string comparison

Why does this cause an infinite loop? #!/bin/bash while [[ "$(ipcs | awk '{print $2}')" != "Semaphore" ]]; do #Gonna get rid of the echo after working echo "$(ipcs | awk '{print $2}')" #I wanna ...
0
votes
1answer
104 views

Bash if statement [: missing `]' error [duplicate]

I am having trouble with bash. I am trying to put a command in an if statement and then compare it to a string. This works perfectly. echo $(ipcs | grep Shared | awk '{print $2}') When I put it in ...
2
votes
4answers
71 views

replace several comma out side one or more sets of curly braces and exception that in one or more sets of curly braces

In the text file I have multi records. Every record has multi column with comma separated, some column have one sets of curly brace and other have more than one curly brace. I need: If a comma is ...
0
votes
0answers
29 views

Why are my directories and files created with bashscripts ending with \r? (Script Example) [duplicate]

Okay so I'm really confused but that is cause I know next to nothing about bash scripting. My problem is when I get the script to work it creates directories and files with the \r ending and that ...
1
vote
3answers
123 views

bash script that reads user input and uses “cal” command to validate dates

I want to write a script that reads my input (for example if my script is called "check", then I would type "check 9 4 1993" and that input would go through the cal command and will check through the ...
1
vote
0answers
26 views

Get path of currently marked file

Im running OS X and I'm wondering if there is a way to get the path of the currently marked file in Finder. Like, can UNIX determine what file i have clicked on? Reasons for this would be for ...
4
votes
2answers
584 views

How do I delete all of a set of files in a random order?

I have a set of files, all that are named with the convention file_[number]_[abcd].bin (where [number] is a number in the range 0-size of drive in MB). i.e there is file_0_a.bin, file_0_b.bin, ...
1
vote
1answer
26 views

View timestamp for CUPS print jobs

I'm looking for a way to view the timestamp of a job in CUPS. I've searched the man pages and can't seem to find it. The long term goal is to have a script that parses the time from the jobID and ...
2
votes
4answers
62 views

How to remove part of a string

I keep reading the sed documentation and lots of posts but can't seem to figure this out. I have a large number of Java files. In those files are calls to a method that take the enumeration converted ...
-1
votes
2answers
68 views

Edit a file in /etc using shell scripting?

How do I use sed to edit the file /etc/heat/heat.conf? I want to add the new lines under the default section [DEFAULT] rabbit_host =controller rabbit_password =RABBIT_PASS
-4
votes
1answer
43 views

How to use Sed to replace all characters in between colons

How to replace all characters between colons using sed? # replace easy with 123 sed:easy:abc -> sed:123:abc # replace hardest with 123 sed:hardest:efg -> sed:123:efg # replace magnificent ...
12
votes
2answers
505 views

How does awk '!a[$0]++' work?

This one-liner removes duplicate lines from text input without pre-sorting. For example: $ cat >f q w e w r $ awk '!a[$0]++' <f q w e r $ The original code I have found on the internets ...
2
votes
4answers
200 views

Passing wildcard * to a (bash?) script [duplicate]

I want to to remove all color codes which look like '@n', '@R' etc, from a moderately large size collection of text files. So in a file called 'remove_cc', I wrote the following: sed -ie 's/@r//g' ...
0
votes
0answers
16 views

running graphics based script with disabled desktop environments on system startup

I'd like to introduce first what I am trying to achieve. I am having a Linux script which requires graphical environment OR which is graphical(I am myself not sure what I am trying to make others ...
1
vote
2answers
39 views

A script for making another script deal with all files in sequence?

I have found a nicely working script to convert pdf files into txt format, with ocr. But it converts only one pdf file each time. I need to mass-convert them. I have no knowledge of script ...
1
vote
1answer
45 views

Regex works in shell but not through Perl script

I'm having trouble executing a Perl script through the Unix shell using Perl's system command. I've had more complex regex commands I had to adjust accordingly to convert from Unix to Perl, and ...
8
votes
2answers
493 views

How to non-invasively test for write access to a file?

In a shell script, how do I easily and non-invasively test for write access to a file without actually attempting to modify the file? I could parse the output of stat, but that seems really complex, ...
2
votes
1answer
179 views

How to remove file log with file name

Assume, I have log files with this name format. NameLog.log.2014-09-27 NameLog.log.2014-09-28 NameLog.log.2014-09-29 NameLog.log.2014-09-30 NameLog.log.2014-10-01 NameLog.log.2014-10-02 ...
1
vote
1answer
42 views

Replace new lines char (^M) in all files and then rename file based on char string

I am not a UNIX guy but understand enough to gin up small scripts here and there except for this one where I may personally be not able to devote enough time. I have about 2000 files in a directory ...
-1
votes
2answers
47 views

Using 'sed' to find and replace [duplicate]

I know this question has probably been answered before. I have seen many threads about this in various places, but the answers are usually hard to extract for me. I am looking for help with an ...
5
votes
7answers
401 views

Decoding URL encoding (percent encoding)

I want to decode URL encoding, is there any built-in tool for doing this or could anyone provide me with a sed code that will do this? I did search a bit through unix.stackexchange.com and on the ...
2
votes
1answer
46 views

Read two text files, concatenate each line

I have two text files of the same length, in order: one of products, the other of comparison products. I'd like the output to be "product;comparison" for each line. Yes I could throw them in a ...
0
votes
3answers
54 views

How to run a script in multiple instances ? ( Ubuntu server )

How can I run a script in multiple instances in Ubuntu server? For example, I have a long running script named scanner.sh placed in /usr/bin/, which I wish to run the script in 10 parallel ...
1
vote
2answers
52 views

A tiny and simple script fail and this is the output “No such file or directory”

The script is: #!/bin/bash IFS=" " command="ls /tmp" for file in `$command`; do echo $file done And the output is: $ ./test.sh ./test.sh: line 17: ls /tmp: No such file or directory
1
vote
1answer
36 views

ffmpeg script - slicing a video into multiple slices

I am currently using ffmpeg to slice video files. I automated the process through a script called ffmpeg_split.sh. To view the script click here. When I run the script I have an error when trying to ...
-3
votes
1answer
50 views

How to use `cal` to run scripts? [closed]

I wrote a script and need to make it run with the cal command. How do I do this? This is my .bashrc: PATH=/usr/local/bin:/usr/bin:/bin:/usr/bin/X11:/lib/ast/bin:/home/$USER/bin:.
9
votes
4answers
238 views

Unexpected EOF and syntax error

I am currently writing my third ever shell script and I have run into a problem. This is my script so far: #!/bin/bash echo "choose one of the following options : \ 1) display all current users \ ...
2
votes
2answers
62 views

Add Text to Command Line via Shell Script

I have a shell script which is opening different terminals. After opening the terminals, I manually start different applications in the terminals. I would like to automate this by adding text (e.g. ...
3
votes
2answers
63 views

How can I run a script when internet connection is about to get lost?

I use wvdial (PPP dialer) with sim card modem and sometimes this connection is reset by server side. I would like to run a script which greps ifconfig to get a volume of data downloaded and stores it ...
4
votes
3answers
155 views

Script to compare 2 input paramters and show shared letter(s)

I am writing a script that I want a user to enter two separate words, and the result to show which letter the two words share. For instance ./share Cat Rat - would return shared letters: "a" and "t". ...
1
vote
2answers
54 views

Find and for loop

Trying to do a mass convert from M4A to OGG in a large music collection, I have: #!/bin/sh for i in `find /home/family/Music -name *.m4a -print0` #do ffmpeg -i "$i" -acodec libvorbis -aq 6 -vn -ac ...
4
votes
2answers
126 views

When is 'if' not necessary?

In some scripts, I've seen if conditional statements written as: if [ some_conditional_statement ]; then # do stuff fi or [ some_conditional_statement ] && #do stuff Is the second ...
2
votes
1answer
26 views

bash_logout only run command on last logout

This command is in my .bash_logout script to delete a temporary directory when I logout after running some processing: /bin/rm -rf /tmp/tmpdir/ However, I usually have more than one connection to a ...
0
votes
1answer
36 views

Command to list all usernames on a Linux server

What is the command that allows one to generate a list of all the usernames of authorised users on a Linux server? I have tried getent passwd | cut -d : -f 1 | xargs groups and less ...
3
votes
3answers
183 views

How to copy, execute and retrieve data from a remote computer?

I am trying to run some calculations on a remote computer. Basically I want to copy some files to the computer, load a software, execute the calculation, then retrieve the data back. I have created a ...
2
votes
2answers
56 views

How to get grep exit code but print all lines?

I'd like to check whether a line printed by a command contains an error message, but I'd like to also print all the output from the command (for make logs). Is there some way to get all the output of ...
2
votes
2answers
85 views

Shell script to merge files with same names

I have a directory of files such as: file.1111111_1.pdf file.1111111_2.pdf file.2222222_1.pdf file.2222222_2.pdf … file.1234567_1.pdf file.1234567_2.pdf … file.aaaaaaa_1.pdf file.aaaaaaa_2.pdf … ...
3
votes
1answer
87 views

Finding largest file recursively

I am trying to find the largest file in a directory recursively. If there is a subdirectory inside of that directory the function needs to go inside that directory and check to see if the largest file ...
0
votes
1answer
68 views

Very basic H/W question using pipe and grep

I have two text files, F1a.txt and F1b.txt, with essentially the same data: the driver's surname and their nationality. For example: Hamilton GBR Alonso SPA I have concatenated these ...
-2
votes
1answer
653 views

convert CSV to XLS file on linux [closed]

The following Perl script can convert CSV file to XLS file the problem is that I need to install on customer Linux machine many Perl modules in order to run this Perl script , and actually I cant ...
0
votes
1answer
119 views

Using Grep Colour to look in a file, and output with a coloured answer in amongst the file contents

I am currently in the process of writing a program in raspberry pi that will allow me to look inside files and have what I entered displayed in colour I think I need to do something to do with ...