The following test is in CentOS 7.1. Create the following file test.service in /usr/lib/systemd/system/ and execute systemctl daemon-reload; systemctl restart test; systemctl status test -l There is no output of the value as the ${a} does not substitute as the word hello world, until it is changed echo ${a} i…
Tag: bash
Inserting strings to file names with different extensions
I have a number of files of different type in a directory: file, file0, file.txt, file.jpg etc. Some with extensions, some without. I want to rename files in a directory by inserting ‘final’ to them. So they would appear as: filefinal, file0final, filefinal.txt, filefinal.jpg etc. I imagine that t…
Chef – using a for loop with SQLEOH
I have a bash resource which is failing when attempting to loop through some ddl scripts. The same syntax without a for loop (and literal script name) works fine in Chef, and it all works including with the for loop in a terminal: The errors I am getting indicate a problem with the SQLEOH delimiter and unexpe…
How to make “tar –exclude” behave consistently across *nix environments?
I am writing a bash script to make a deployment tarball and the script must work across OSX and Linux. I have a directory structure as shown below and in a bash script I need to tar the contents excluding ./foo but including ./baz/foo Simple! Normally I would do this by passing –exclude=’./fooR…
How to find files that contain two or more of a specific character?
I’m learning about wildcards and I’m trying to figure out how to find filenames that contain a specific character, two or more times. For example, finding filenames that have two or more x’s in them, such as Xerox. I know how to find files that have an *x, or that have an *ox*, but I canR…
Change all non-ascii chars to ascii Bash Scripting
I am trying to write a script that take people names as an arguments and create a folder with their names. But in folder names, the non-ascii chars and whitespaces can sometimes make problem so I want to remove or change them to ascii chars. I can remove the whitespace between name and surname but I can not f…
How to Run Multiple Time Same Code in Bash
How can i run multiple times this same code? For example 12 times? All the code belove must be replicated N times something like But it does not work for multiple lines of command. Any issue? Answer Using a while loop and a counter:
Send Command to serial port via Cu and exit in same line
I want to execute “sw i01” into cu command and exit cu (with “~.”) in just one line or in file bash because il will execute them from a distant server In this image i put: then it return “Connected.” i put “sw i01” (command switch HDMI to input 1) it return R…
renaming file using shell script
I have tons of image inside a folder and it also has different file types. I have tried googling for an answer but I can’t seem to find one. I wanted the files to be named 1.jpg, 2.png, 3.gif. . . n.JPEG. Could someone help me out with this? Answer Try the command below: Make note that the command above
Removing specific string from lines in file using sed
I have a file like so: I want the following output: What I tried is: But this is not what I want… Answer Try this way