Tag Info

Hot answers tagged

10

Solution 1: Bash functions Bash functions behave much the same like commands. You can put functions into - for example - your ~/.bashrc file, like hello() { echo Hello World! } Then you can run this like any other command as long as you start it from your shell, and not from a cron job, init script etc: me@pc:~$ hello Hello World! Solution 2: The ...


7

You need to end it with a "done", like: for f in *.jpg do gsettings set org.gnome.desktop.background picture-uri "file:$f" done But I think the best way to do it is like this: for f in /path/to/dir/*.jpg do gsettings set org.gnome.desktop.background picture-uri "file://$f" done Okay, I edited the second code. Try with this. If you want to get ...


5

In bash you end for blocks with a done, like so: for f in *.jpg do gsettings set org.gnome.desktop.background picture-uri "file:$f" done Also, put double quotes around $f, in case some file names contain spaces. Note that I think what you are trying to achieve could be done easier with find: find $imageDir -maxdepth 1 -type f -name "*.jpg" ...


4

Add the last line: done. Also, put double quotes around $f, in case some file names contain spaces. Thus, the whole script becomes: for f in *.jpg do gsettings set org.gnome.desktop.background picture-uri "file:$f" done


4

First, basic bash syntax: a for loop ends with the reserved word done. for f in *.jpg do gsettings set org.gnome.desktop.background picture-uri file:$f done Furthermore $f is a relative path — it's a file name in the current directory. But as feyray remarked that file name would not be meaningful out of context. You need to provide an absolute path. ...


4

You need to add the ./ to run commands from scripts in the local directory, because commands that do not contain / in their name are looked up only in the directories mentioned in the $PATH value. Normally that value contains only absolute paths, and in particular does not contain a path ., so that the current working directory is not looked at. This is a ...


4

I'd be highly surprised if the ftp://server/file protocol permits wildcards. I suspect you'll have to fetch a list of the available files and iterate over the ones with 2 digits. However if you want to generate the numbers 00 to 99 in bash: for file in {0..9}{0..9}.png; do ...


3

This one works for sure, just tested it and it's exactly what you want: nmap -p 1-1023 -sV host | head -n -5 | tail -n +7 | awk '{print substr($0, index($0, $3))}' index finds the 3rd column and returns its position to substring which then marks that position in whole line $0. All of this is then sent to print which displays it. Default field separator ...


3

As g_p said in the comments, your if [ "$CURNUM" -lt "$_MAXNUM" ] isn't terminated. Bash is expecting a fi before the while's done.


2

Use Bash's filename expansion (using *, ? and []): $ ls 00.png 03.png 06.png 09.png 12.png 15.png 18.png 21.png 01.png 04.png 07.png 10.png 13.png 16.png 19.png 02.png 05.png 08.png 11.png 14.png 17.png 20.png $ files=([0-9][0-9].png) $ echo "${files[@]}" 00.png 01.png 02.png 03.png 04.png 05.png 06.png 07.png 08.png 09.png 10.png 11. png ...


2

You can prepend sudo to all the commands. Make sure to run the script as root, the unprivileged user will be put in as needed #/bin/bash do-something-neat # Run as invoking user (root) sudo -u randomuser do-something-else # Run as "randomuser" user make potato --type=Mashed # Run as invoking user (root) ...


2

Section Parameter Expansion (extract) from bash's manpage: ${parameter,,pattern} Case modification. This expansion modifies the case of alphabetic characters in parameter. The pattern is expanded to produce a pattern just as in pathname expansion. The ^ operator converts lowercase letters matching ...


1

seq prints a sequence of numbers. -w equalizes width by padding with leading zeroes. files=`seq -w 0 99` for file in $files do curl ftp://server/${file}.png done


1

What you were doing "-u username:password" is as far as I know a HTTP basic authentication which is different from filling out a form and sending it via POST. This should work: #!/bin/bash pages="0.php 1.php 2.php" for page in ${pages}; do wget -q --post-data 'user=username&password=password' --save-cookies cookies "http://server/${page}" wget -O- ...


1

create a file and put smth like #!/bin/bash useradd "$1" && gpasswd -a "$1" group in there.


1

Your question is a bit vague because you haven't really said what you need this for. I'm assuming you need arguments as well so first create the script, so in the terminal type nano scriptname.sh and past in the script below. #!/bin/bash #$1 username #$2 home directory useradd $1 -U -m -d $2 If you type 'man useradd' you will see that -U creates a ...


1

Welcome to the wonderful hell of IMAP ;-) You can use python to do that: #!/usr/bin/env python # -*- coding: utf-8 -*- from __future__ import unicode_literals from email.parser import HeaderParser import imaplib, email, re list_response_pattern = re.compile(r'\((?P<flags>.*?)\) "(?P<delimiter>.*)" (?P<name>.*)') def ...


1

Try adding an ampersand at the end of the lines to put processes into background. #!/bin/bash gnome-terminal -x /bin/bash haguichi -d & cd /home/reed/StarMade gnome-terminal -x java -jar StarMade.jar -force & gnome-terminal -x ./StarMade-dedicated-server-linux.sh &



Only top voted, non community-wiki answers of a minimum length are eligible